本文链接:https://blog.csdn.net/pansaky/article/details/86599280
/*usage: cc mem.c -o mem.out 后 使用./mem.out 100 & 消耗对应数字MB单位的内存,释放时杀掉对应进程即可*/
#include
#include
#include
#define UNIT (1024*1024)
int main(int argc, char *argv[])
{
long long i = 0;
int size = 0;
if (argc != 2) {
printf(" === argc must 2\n");
return 1;
}
size = strtoull(argv[1], NULL, 10);
if (size == 0) {
printf(" argv[1]=%s not good\n", argv[1]);
return 1;
}
char *buff = (char *) malloc(size * UNIT);
if (buff)
printf(" we malloced %d Mb\n", size);
buff[0] = 1;
for (i = 1; i < (size * UNIT); i++) {
if (i%1024 == 0)
buff[i] = buff[i-1]/8;
else
buff[i] = i/2;
}
pause();
}
————————————————
版权声明:本文为CSDN博主「天健胡马灵越鸟」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/pansaky/article/details/86599280
阅读(2282) | 评论(0) | 转发(0) |