首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FileChannel transferFrom的注释解释

FileChannel transferFrom的注释解释
EN

Stack Overflow用户
提问于 2013-06-26 10:24:34
回答 1查看 306关注 0票数 1

我读过FileChannel's transferFrom上的评论

代码语言:javascript
复制
 * <p> This method is potentially much more efficient than a simple loop
 * that reads from the source channel and writes to this channel.  Many
 * operating systems can transfer bytes directly from the source channel
 * into the filesystem cache without actually copying them.  </p>

这是什么意思?

代码语言:javascript
复制
Many operating systems can transfer bytes directly from the source channel
into the filesystem cache without actually copying them.

如果我从一个通道读取,然后将其写入另一个通道,它不会将字节传输到缓存中吗?

EN

回答 1

Stack Overflow用户

发布于 2013-06-26 10:43:16

是的,如果您使用循环并从源通道读取到ByteBuffer,然后将ByteBuffer写入FileChannel,则在写入结束时,字节/数据将位于文件系统缓存中。它们还将被复制到Java中,这可能是从内核复制到应用程序内存(或"C堆“),然后再复制到ByteBuffer堆(在最坏的情况下)。

如果源通道是兼容的,则OS可能能够避免复制到JVM堆中,甚至可能完全从内核之外,而是直接从比方说源文件页复制到目标文件页中。

如果您将看到任何真正的性能改进,将高度依赖于JVM版本、操作系统和文件系统。我认为它的性能不会比Java代码的循环差。

罗伯。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17310565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档