Ticket #3183: memory_part2.c

File memory_part2.c, 549 bytes (added by Jixt, 11 years ago)
Line 
1/* Reallocate up to 64*1024*1000 bytes */
2
3
4#include <stdlib.h>
5#include <stdio.h>
6
7#define READLEN 64*1024
8
9int main()
10{
11 unsigned char *data = NULL;
12 int i;
13 unsigned long curoff = 0;
14
15 printf("Allocating memory ...");
16
17 while(1)
18 {
19 curoff = 0;
20 data = malloc(READLEN);
21 curoff += READLEN;
22 for(i = 0; i <= 1000; i++)
23 {
24 data = realloc(data, curoff + READLEN);
25 curoff += READLEN;
26 if(i % 100 == 0)
27 printf("Reallocated to %d bytes.\n",curoff);
28 }
29 printf("Free %d of allocated memory.\n",curoff);
30 free(data);
31 }
32 return 0;
33}