c#字节文件从磁盘加载时间 [英] c# Byte File load time from disk

查看:68
本文介绍了c#字节文件从磁盘加载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我将文件加载到内存中,我注意到它可能会花费截然不同的时间.

我将整个文件读取为字节流,并且文件大小为1G.通常,我第一次加载新创建的文件-加载速度很快-大约需要1秒.

然后,当我重建代码并再次加载时-加载同一文件可能需要30到60秒.

有人可以告诉我为什么吗?

Hi,

I load a file into memory and I have noticed that it can take radically different amounts of time.

I read whole file as a byte stream and file is 1G in size. Usually the first time I load a newly created file - it loads fast - in about 1 second.

Then when I rebuild my code and load it again - the same file can take 30 to 60 secs to load.

Can anyone tell me why?

推荐答案

如果它是新创建的文件,则很有可能大部分仍在缓存中:它是在计算机的内存以及磁盘中(实际上可能尚未到达磁盘).

如果它在内存中,则PC不需要从硬盘驱动器读取它,因此它可以更快地加载它.

第二次,您重新构建了程序,因此文件占用的某些内存已被VS重新使用.因此,当您访问文件时,必须从HDD读取文件.

硬盘访问速度比主存储器要慢得多!
If it is a newly created file, then there is a good chance that the bulk of it is still in the cache: it is in your computer''s memory as well as on disk (in fact it may not have reached the disk yet).

If it is in memory, then the PC does not need to read it from the hard drive, so it can load it a lot quicker.

The second time, you have rebuilt your program, so some of the memory taken up by the file has been re-used by VS. So when you access the file, it has to be read from the HDD.

Hard drives are very very much slower to access than main memory!


这篇关于c#字节文件从磁盘加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆