WEB开发网
开发学院软件开发VC File Mapping析疑 阅读

File Mapping析疑

 2008-09-23 19:27:20 来源:WEB开发网   
核心提示: You should not use file mapping in the following situations:You want to read a file sequentially from start to finish only once.The file is sever

You should not use file mapping in the following situations:

You want to read a file sequentially from start to finish only once.

The file is several hundred megabytes or more in size. (Mapping large files fills virtual memory space quickly. In addition, your program may not have the available space if it has been running for a while or its memory space is fragmented.)

问题五、为什么在操作大文件时速度变得很慢呢?

遇到这个问题,你可以首先打开Windows的任务管理器,看看你进程究竟使用了多少的内存。呵呵,通常都是个天文数字。占用了那么多的内存,系统肯定就很慢了。遇到这样的问题,我们通常都是使用内存映射文件对数据文件进行遍历操作,譬如像将A文件拷贝为B文件。上面我们提到,操作系统是在真正用到数据的时候才会把它从数据文件中提交到物理内存里面的,因此,刚做好映射不进行操作的话,进程并不会消耗多少内存。但是,一旦你开始进行遍历,那么,操作系统就马上将它们调入物理内存中(你可以看看页面错误的数量,肯定是飞速增长的),于是,内存就一路飞涨了。

怎么办呢?不要一次性把整个文件进行映射,而是分开进行,操作完一部分后,将它unmap掉,这样,操作系统就会把它们“赶回家去”了,内存就不会占用太高了。

Reference:

[1] Computer Systems:A Programmer's Perspective ,Chapter 10 Virtual Memory

[2] Memory Management

[3]Virtual Memory and Memory Mapping

[4] Mapping Files Into Memory

文章来源: http://hi.baidu.com/daping_zhang/blog/item/5e34843511d2f51190ef3902.html

上一页  1 2 3 4 

Tags:File Mapping 析疑

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接