Boost managed_mapped_file:设置允许的最大内存使用率
Boost managed_mapped_file: setting maximum allowed memory usage
有什么方法可以设置managed_mapped_file
使用的最大允许内存吗?例如,我有64GB的内存,我创建了一个20GB的文件。这些都已加载到内存中。例如,有没有办法指定只使用1GB的内存?即使近似也足够了。
编辑:我应该添加我使用boost::interprocess::vector
。。也许有一种方法可以专门化分配器?
typedef bi::allocator<Node, bi::managed_mapped_file::segment_manager> allocator_node_t;
typedef bi::vector<Node, allocator_node_t> vector_node_t;
bi::managed_mapped_file* nodeFile = new bi::managed_mapped_file(bi::open_or_create, "nodes_m.bin", bigSize);
allocator_node_t alloc_n(nodeFile->get_segment_manager());
vector_node_t* nodes = nodeFile->find_or_construct<vector_node_t>("nodes")(alloc_n);
没有这样的方法(便携)。
前提也是错误的:
例如,我有64GB的内存,我创建了一个20GB的文件。这些都加载到内存中
错误:它将只加载所使用的页面。是的,这可能意味着你最终可能拥有完整的20GB内存。只要没有其他进程需要物理内存来执行其他任务,操作系统就可以自由执行。
操作系统出于任何原因任意取消映射数据都是愚蠢的。您希望操作系统利用可用内存。否则,那些硅片上的钱就浪费掉了。
编辑:我应该添加我使用的boost::interprocess::vector。。也许有一种方法可以专门化分配器?
在没有自定义分配器的情况下使用boost::interprocess::vector
首先不会使用共享内存。首先需要使用例如boost::interprocess::allocator<T, boost::interprocess::managed_mapped_file::segment_manager>
来使用映射文件。
不,分配器中的任何东西都不能覆盖操作系统虚拟内存调整参数。
没有什么需要专门化(在C++的意义上)
bi::managed_mapped_file* nodeFile = new bi::managed_mapped_file(bi::open_or_create, "nodes_m.bin", bigSize); allocator_node_t alloc_n(nodeFile->get_segment_manager()); vector_node_t* nodes = nodeFile->find_or_construct<vector_node_t>("nodes")(alloc_n);
第一次执行此代码(即创建"nodes_m.bin")将不会加载bigSize
。事实上,它甚至不会在磁盘上分配bigSize
!在所有支持它的系统上(据我所知,没有主流操作系统不支持它),该文件是创建的稀疏。
- 将字符串存储在c++中的稳定内存中
- C++ 指针的内存地址和指向数组的内存地址如何相同?
- Win32编译器选项和内存分配
- 当vector是tje全局变量时,c++中vector的内存管理
- 带内存和隔离功能的SQLite
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 迭代时从向量和内存中删除对象
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 为什么示例代码访问IUnknown中已删除的内存
- 如何在C++类内存结构中创建"spacer"?
- 从构造函数抛出异常时如何克服内存泄漏
- malloc() 可能出现内存泄漏
- 如何理解将半精度指针转换为无符号长指针和相关的内存对齐
- 在调用FreeLibrary后,释放动态链接到具有相同版本的CRT堆的DLL的内存
- 如何针对特定情况调试和修复此双自由内存损坏问题
- 类型总是使用其大小存储在内存中吗
- 有没有一种方法可以测量c++程序的运行时内存使用情况
- 有没有一种方法可以使用placement new将堆叠对象分配给分配的内存