Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. //Allocate 4 quarters.
  2. void* q1 = malloc((HEAP_SIZE / 4) - 24);
  3. void* q2 = malloc((HEAP_SIZE / 4) - 24);
  4. void* q3 = malloc((HEAP_SIZE / 4) - 24);
  5. void* q4 = malloc((HEAP_SIZE / 4) - 24);
  6. //Free the middle two.
  7. free(q2);
  8. free(q3);
  9. //Malloc the middle two quarters out again.
  10. void* center = malloc((HEAP_SIZE / 2) - 48);
  11. center++;
  12. int wantedMallocCount = 5;
  13. if(wantedMallocCount != mCount){
  14. printf("Malloc was called %ld times, but we want %d calls.", mCount, wantedMallocCount);
  15. }
  16. free(q1);
  17. free(q4);
  18. if(fCount != 4){
  19. printf("Something wrong with free. Free was called 4 times, but count was %ld", fCount);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement