/* * churn.c * * usage: churn [-v] maxblock\n"); * * Allocate & free memory * * Tests malloc() and free() by repeatedly allocating and freeing * chunks of memory of up to size maxblock. * * -v is verbose mode, and prints a message with each call to malloc/free * * Bryan Clair 2002-2013 * v2.0 2010: churn now actually writes data into the memory it's allocated, and checks * that the data survives. */ #include #include #include #include #include // At any time, churn may have up to NUMSLOTS memory allocations #define NUMSLOTS 40 char *slots[NUMSLOTS]; size_t sizes[NUMSLOTS]; main(int argc, char *argv[]) { int i,n,size,maxblock; long j; int verbose=0; // Read arguments maxblock = -1; if (argc == 3) { if (!strcmp(argv[1],"-d")) { maxblock = atoi(argv[2]); verbose = 1; } } if (argc == 2) maxblock = atoi(argv[1]); if (maxblock <= 0) { fprintf(stderr,"usage: churn [-d] maxblock\n"); exit(1); } // Initialize for (i = 0; i