4
为什么这个吃记忆的人真的不吃记忆?
我想创建一个程序来模拟Unix服务器上的内存不足(OOM)情况。我创建了这个超级简单的内存消耗者: #include <stdio.h> #include <stdlib.h> unsigned long long memory_to_eat = 1024 * 50000; size_t eaten_memory = 0; void *memory = NULL; int eat_kilobyte() { memory = realloc(memory, (eaten_memory * 1024) + 1024); if (memory == NULL) { // realloc failed here - we probably can't allocate more memory for whatever …
150
c
linux
memory
virtual-memory