boost :: memory-mapping~500MB,外部USB文件的问题

时间:2013-08-31 22:35:58

标签: c++ boost memory-mapped-files

我使用以下代码打开大小约为400到800MB的文件:

#include <boost\interprocess\file_mapping.hpp>
#include <boost\interprocess\mapped_region.hpp>
#include <iostream>
#include <vector>
#include <string>

using namespace boost::interprocess;
using namespace std;

int main(){
    file_mapping fm("C:\\test\\1.txt",read_only);
    mapped_region region(fm,read_only);
    const char* const data = static_cast<const char*>(region.get_address());
    const size_t max_size = region.get_size();

    cout << max_size;

    int b;
    cin >> b;
}

如果我将上面的代码指向一个小文件,我就不会有异常。但是,当查看几百MB文件(在外部USB上)时,我得到一个例外:

  

ReadingFiles.exe中0x7521C41F处的未处理异常:Microsoft   C ++异常:内存中的boost :: interprocess :: interprocess_exception   位置0x0040FBD4。

我有2.4GB的RAM空闲 - 所以它不应该是我的内存耗尽了吗?

1 个答案:

答案 0 :(得分:0)

如果您的程序编译为32位程序,则很可能内存不足。有点。 2.4GB免费并不一定意味着2.4GB免费连续内存。您可能无法获得足够大的块来映射文件。