1 /* 2 * $DragonFly: src/tools/test/malloc/main.c,v 1.2 2003/11/07 14:38:38 eirikn Exp $ 3 */ 4 5 #include <stdlib.h> 6 #include <stdio.h> 7 #include <unistd.h> 8 9 u_long NBUCKETS = 2000; 10 u_long NOPS = 200000; 11 u_long NSIZE = (16*1024); 12 13 char **foo; 14 15 int 16 main(int argc, char **argv) 17 { 18 int i,j,k; 19 20 if (argc > 1) NOPS = strtoul(argv[1],0,0); 21 if (argc > 2) NBUCKETS = strtoul(argv[2],0,0); 22 if (argc > 3) NSIZE = strtoul(argv[3],0,0); 23 printf("BRK(0)=%x ",sbrk(0)); 24 foo = malloc (sizeof *foo * NBUCKETS); 25 memset(foo,0,sizeof *foo * NBUCKETS); 26 for (i = 1; i <= 4096; i+=i) { 27 for (j = 0 ; j < 40960/i && j < NBUCKETS; j++) { 28 foo[j] = malloc(i); 29 } 30 for (j = 0 ; j < 40960/i && j < NBUCKETS; j++) { 31 free(foo[j]); 32 foo[j] = 0; 33 } 34 } 35 36 for (i = 0 ; i < NOPS ; i++) { 37 j = random() % NBUCKETS; 38 k = random() % NSIZE; 39 foo[j] = realloc(foo[j], k & 1 ? 0 : k); 40 if (foo[j]) 41 foo[j][0] = 1; 42 } 43 printf("BRK(1)=%x ",sbrk(0)); 44 for (j = 0 ; j < NBUCKETS ; j++) { 45 if (foo[j]) { 46 free(foo[j]); 47 foo[j] = 0; 48 } 49 } 50 printf("BRK(2)=%x NOPS=%lu NBUCKETS=%lu NSIZE=%lu\n", 51 sbrk(0),NOPS,NBUCKETS,NSIZE); 52 return 0; 53 } 54