小编cgk*_*cgk的帖子

Linux:由于虚拟内存限制,无法在单个进程中分配超过32 GB/64 GB的内存

我有一台128 GB RAM的计算机,运行Linux(3.19.5-200.fc21.x86_64).但是,我不能在一个进程中分配超过~30 GB的RAM.除此之外,malloc失败了:

#include <stdlib.h>
#include <iostream>

int main()
{
   size_t gb_in_bytes = size_t(1)<<size_t(30); // 1 GB in bytes (2^30).
   // try to allocate 1 block of 'i' GB.
   for (size_t i = 25; i < 35; ++ i) {
      size_t n = i * gb_in_bytes;
      void *p = ::malloc(n);
      std::cout << "allocation of 1 x " << (n/double(gb_in_bytes)) << " GB of data. Ok? " << ((p==0)? "nope" : "yes") << std::endl;
      ::free(p);
   }
}
Run Code Online (Sandbox Code Playgroud)

这会产生以下输出: …

linux memory

11
推荐指数
1
解决办法
3015
查看次数

标签 统计

linux ×1

memory ×1