在C ++中读取二进制文件而不将整个文件缓冲到内存中 [英] Reading binary files without buffering the whole file into memory in C++

查看:135
本文介绍了在C ++中读取二进制文件而不将整个文件缓冲到内存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了做一个二进制比较器我试图使用CreateFileW函数读取两个文件的二进制内容。但是,这会导致整个文件被缓冲到内存,这成为大(500MB)文件的问题。



我已经找到了其他函数,让我只是缓冲部分的文件,但我没有找到任何文档,具体说明如何缓冲区工作对我有用[0]丢个板砖[0]引用举报发新话题发新话题发新话题发新话题发短消息加为好友它似乎有一个可定义的缓冲区,但我不完全确定将不会有另一个缓冲区实现在幕后,像使用CreateFileW。



你们对什么是好功能有什么意见?

解决方案

您可以使用内存映射文件来执行此操作。打开 createFile ,使用 createFileMapping 然后 MapViewOfFile 指向数据的指针。


In order to make a binary comparer I'm trying to read in the binary contents of two files using the CreateFileW function. However, that causes the whole file to be bufferred into memory, and that becomes a problem for large (500MB) files.

I've looked around for other functions that'll let me just buffer part of the file instead, but I haven't found any documentation specifically stating how the buffer works for those functions (I'm a bit new at this so maybe I'm missing the obvious).

So far the best match I seem to have found is ReadFile. It seems to have a definable buffer but I'm not completely sure that there won't be another buffer implemented behind the scenes, like there is with CreateFileW.

Do you guys have any input on what would be a good function to use?

解决方案

You could use memory mapped files to do this. open with createFile, use createFileMapping then MapViewOfFile to get a pointer to the data.

这篇关于在C ++中读取二进制文件而不将整个文件缓冲到内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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