test.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <stdio.h>
  2. #include "heap.h"
  3. #include "other.h"
  4. #include "posix_lock.h"
  5. #include "LeaHeader.h"
  6. #include "dmm_init.h"
  7. /*
  8. void *first_fit_search(unsigned int size, NODE *starting_node,
  9. char is_fixed_global) {
  10. NODE *node;
  11. node = starting_node;
  12. while(node) {
  13. }
  14. }
  15. */
  16. void *custom_malloc(heap_t* heap, size_t size);
  17. void *custom_malloc(heap_t* heap, size_t size) {
  18. void *ptr;
  19. int fixed_list_id, i;
  20. MAPTABLE_NODE *current_maptable_node;
  21. ptr = NULL;
  22. posix_lock(heap);
  23. fixed_list_id = map_size_to_list(heap, size);
  24. // If a fixed list is found, do a first fit
  25. if(fixed_list_id != -1) {
  26. current_maptable_node = heap->maptable_head;
  27. // traverse through the maptable node list
  28. if(fixed_list_id != 0) {
  29. for(i = 1; i < fixed_list_id; i++) {
  30. current_maptable_node = current_maptable_node->next;
  31. }
  32. }
  33. ptr = current_maptable_node->fixed_list_head;
  34. current_maptable_node->fixed_list_head = ((NODE *) ptr)->next;
  35. set_requested_size(ptr, size);
  36. markInUse(ptr);
  37. }
  38. if(ptr == NULL) {
  39. // first fit from free list
  40. }
  41. posix_unlock(heap);
  42. return ptr;
  43. }
  44. int main(void) {
  45. allocator_t *myallocator;
  46. heap_t *myheap;
  47. int heap_id;
  48. myallocator = dmm_init();
  49. heap_id = map_thread_heap();
  50. printf("This thread accesses heap %d\n", heap_id);
  51. myheap = &myallocator->heaps[heap_id];
  52. }