在 Java 和 .Net 中从 DVD 读取速度非常慢

发布于 2024-08-04 16:09:57 字数 545 浏览 2 评论 0原文

我注意到在两个生成文件哈希的应用程序(一个用 Java 编写,另一个用 C# 编写)中,从 DVD 读取时的性能非常糟糕。我使用的是Windows XP SP3。我从噪音中注意到,驱动器在读取一堆块后不断旋转,导致读取之间有几秒钟的暂停。

奇怪的是,当我使用资源管理器将文件复制到硬盘驱动器或使用 md5sum(用 C 编写的实用程序)时,不会发生这种情况。还。当使用相同硬件在 Linux 中运行时,Java 应用程序运行良好。

private static final byte[] m_buf = new byte[1048576*3];
...
//Using a BufferedInputStream makes no difference
InputStream in = new FileInputStream(file);
while((last_read = in.read(m_buf)) != -1){
    update_hash(m_buf, 0, last_read);           
}
in.close();

有什么提示吗?

谢谢。

I noticed in two applications to generate hashes of files, one written in Java and the other in C#, that the performance is horrible when reading from a DVD. I'm using Windows XP SP3. I noticed from the noise, that the drive keeps spinning down after reading a bunch of blocks, causing pauses of a couple of seconds between reads.

The strange thing, is that this doesn't happen when I use explorer to copy the files to my hard drive or when using md5sum (a utility written in C). Also. When running in Linux using the same hardware, the Java application works fine.

private static final byte[] m_buf = new byte[1048576*3];
...
//Using a BufferedInputStream makes no difference
InputStream in = new FileInputStream(file);
while((last_read = in.read(m_buf)) != -1){
    update_hash(m_buf, 0, last_read);           
}
in.close();

Any hints?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我只土不豪 2024-08-11 16:09:58

将缓冲区大小减少到 1024 字节后,问题就消失了。
不知道确切的解释,但可能是因为读取更频繁,DVD 驱动器不会降低驱动器的转速。

感谢您的评论

After reducing the size of the buffer to 1024 bytes the problem disappeared.
Don't know the exact explanation, but probably because there are more frequent reads the DVD driver doesn't spin down the drive.

Thanks for the comments

以往的大感动 2024-08-11 16:09:58

我猜测 Java 代码将 DVD 视为文件系统上的常规文件,而 Windows 可能会优化读/写。

由于 Java IO 调用转到本机/操作系统调用,因此我猜测 Linux 操作系统在进行 IO 调用来读取 DVD 时会更聪明。

I'm guessing that Java code treats the DVD as a regular file on the filesystem, while Windows probably optimizes read/write.

Since the Java IO calls go to the native/OS calls, I'm guessing that the linux OS is smarter when making the IO calls to read the DVD.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文