我有一台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)
这会产生以下输出: …