/* * churn2.c * usage: churn2 [-d] maxblock * * Test malloc(), calloc(), realloc() and free() by * repeatedly alloc/freeing NUMSLOTS blocks of memory * of random size between 1 and maxblock. */ #include #include #include #include #include #define NUMSLOTS 32 #define CHURNS 20 long *slots[NUMSLOTS]; int sizes[NUMSLOTS]; main(int argc, char *argv[]) { int i,j,n,size,maxblock; int c=0, f=0, r=0; int d=0; int cc=0; maxblock = -1; if (argc == 3) { if (!strcmp(argv[1],"-d")) { maxblock = atoi(argv[2]); d = 1; } } if (argc == 2) maxblock = atoi(argv[1]); if (maxblock <= 0) { fprintf(stderr,"usage: churn2 [-d] maxblock\n"); exit(1); } for (i = 0; i