自分の環境で使えるヒープの大きさを取得する
エキスパートCプログラミングに書いてあるのとほぼ同じだけど、1MB単位で測る。
あと、メモリが少ない環境の場合はKB単位で測ったほうがいい。
#include <stdio.h> #include <stdlib.h> #define SIZE_KB (1<<10) #define SIZE_MB (1<<20) int main(int argc, char **argv) { int i = 0; while (malloc(SIZE_MB)) i++; printf("%d\n", i); return 0; }