#include <stdio.h> #include <stdlib.h> int main() { int MB = 0; while(malloc(1 << 20)) ++MB; printf("Allocated %d MB total\n",MB); }
为了让程序可以在内存限制的机器上运行,能够把每次分配的1MB改为1KBcode
1 << 20,改为1<<10,用kb代替mb内存