Besides the cool (mostly unnecessary code), you have some problems with variables and loops: your for (int i = 0; i < TEST_LENGTH; i++)... loop for (int i = 0; i < TEST_LENGTH; i++)... , which implements specification step 2, is a loop in which every 100 steps you should print the current statistics, the presence of an external for (int j = 0; j < 1000; j++) loop for (int j = 0; j < 1000; j++) and testing j%100 residues is nonsense.
To debug such a problem, drop two or three zeros from each of the large numbers BLOCK_COUNT, TEST_LENGTH, SIZE_LIMIT, change the j loop limit to 10 and add printf("j=..." ...) after for (int j ...) { so you can tell what is happening. With such changes you will see:
j=0 0 0 0 556736 507760 j=1 0 0 j=2 0 0 j=3 0 0 ...
and then you can conclude that your program seemed to freeze because it slowly counted j to 100 to get to j%100 == 0 .
Now I will talk about two minor elements that need to be removed, and after that the main problem with your program will be mentioned.
Instead
int minimum = 0; int maximum = 0; ... if (i == 0) { maximum = heapsize; minimum = heapsize; } else { if (heapsize > maximum) { maximum = heapsize; } if (heapsize < minimum) { minimum = heapsize; }
records
int minimum = MAX_INT; int maximum = 0; ... if (heapsize > maximum) maximum = heapsize; if (heapsize < minimum) minimum = heapsize;
(or perhaps the MAX_INT option) and (if you need j and / or remainder , what you don't) instead
if (j > 0) { remainder = j % 100; } if (remainder == 0 ) { ...
you write
if (j>0 && j%100 == 0 ) { ...
The main problem with your program: if you say free(ptrList[index]); in part 2, you can free an element on which the current minimum or maximum memory addresses have been indicated. One way to solve this problem is to maintain priority queues with minimum / maximum values ββand fifo discipline; which, in my opinion, is the easiest way to keep track of min / max during distribution, and instead just have a loop to find min / max immediately before each printout.
A small problem with your program: The maximum address used is not ptrList[index] for some index, but ptrList[index]+sizeList[index] .