malloc问题
linux gcc 内存128MB,没有交换分区
#include <stdio.h>
#include <stdlib.h>
#define SIZE 1024*1024
int main(int argc, char **argv)
{
int count = 0;
char *buf = NULL;
while (1)
{
buf = (char *)malloc(SIZE);
if (!buf);
{
break;
}
// memset(buf, 1, SIZE);
printf("current allocated %d MB", count);
}
return 0;
}
注释掉红色部分和放开
结果分别是多少?