memory_test/demo.c

29 lines
366 B
C

#include <stdio.h>
#include <stdlib.h>
#define MB_BYTES (1024*1024)
int main(void)
{
unsigned long *p;
int i = 0;
int nr_mb;
int bytes;
int max;
printf("please specify how many memory to alloc\n");
scanf("%d", &nr_mb);
bytes = nr_mb * MB_BYTES;
max = bytes / 8;
p = malloc(bytes);
for (i = 0; i < max; i++)
*(p + i) = i;
while(1);
return 0;
}