#define CHUNK_SIZE_FROM_INDEX(i) ((1 << ((i) + 5))) #include #include #include #include //will delete later void test_malloc(unsigned int cnt) { void *testchunks[cnt]; unsigned int rindex[cnt], testchunk_size, i, x; bzero(rindex, cnt * sizeof(unsigned int)); for(x = 0; x < cnt; x++) { testchunk_size = (CHUNK_SIZE_FROM_INDEX(randint() % 7) - 24); testchunks[x] = malloc(testchunk_size); //printf("ALLOCATING CHUNK %p SIZE %i\n", (void *)testchunks[x] - 24, testchunk_size); } for(x = 0; x < cnt;) { i = randint() % cnt; if(rindex[i]) continue; rindex[i] = x; x++; } for(x = 0; x < cnt; x++) { //printf("FREEING CHUNK %p\n", (void *)testchunks[rindex[x]]); free(testchunks[rindex[x]]); } printf("\nmalloc tester:\n"); printf("THIS NEEDS TO BE EMPTY______________\n"); debug_heap(); printf("____________________________________\n"); }