test_for_memory_space_aware.c 897 B

12345678910111213141516171819202122232425262728
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dmmlib/initialize_allocator.h>
  4. #include <dmmlib/dmmlib.h>
  5. #define ALLOCATOR_SIZE 16*1024*sizeof(char)
  6. int main(void) {
  7. allocator_t systemallocator;
  8. void *block_from_malloc;
  9. void *p1, *p2, *p3;
  10. block_from_malloc = malloc(ALLOCATOR_SIZE);
  11. initialize_allocator(&systemallocator, block_from_malloc, ALLOCATOR_SIZE);
  12. p1 = custom_ahmalloc(&systemallocator, &systemallocator.heaps[0], (size_t) 1024);
  13. custom_ahfree(&systemallocator, &systemallocator.heaps[0], p1);
  14. p2 = custom_ahmalloc(&systemallocator, &systemallocator.heaps[0], (size_t) 512);
  15. p3 = custom_ahmalloc(&systemallocator, &systemallocator.heaps[0], (size_t) 394);
  16. custom_ahfree(&systemallocator, &systemallocator.heaps[0], p2);
  17. custom_ahfree(&systemallocator, &systemallocator.heaps[0], p3);
  18. free(block_from_malloc);
  19. return 0;
  20. }