#include #include "heap.h" #include "other.h" #include "posix_lock.h" #include "LeaHeader.h" #include "dmm_init.h" /* void *first_fit_search(unsigned int size, NODE *starting_node, char is_fixed_global) { NODE *node; node = starting_node; while(node) { } } */ void *custom_malloc(heap_t* heap, size_t size); void *custom_malloc(heap_t* heap, size_t size) { void *ptr; int fixed_list_id, i; MAPTABLE_NODE *current_maptable_node; ptr = NULL; posix_lock(heap); fixed_list_id = map_size_to_list(heap, size); // If a fixed list is found, do a first fit if(fixed_list_id != -1) { current_maptable_node = heap->maptable_head; // traverse through the maptable node list if(fixed_list_id != 0) { for(i = 1; i < fixed_list_id; i++) { current_maptable_node = current_maptable_node->next; } } ptr = current_maptable_node->fixed_list_head; current_maptable_node->fixed_list_head = ((NODE *) ptr)->next; set_requested_size(ptr, size); markInUse(ptr); } if(ptr == NULL) { // first fit from free list } posix_unlock(heap); return ptr; } int main(void) { allocator_t *myallocator; heap_t *myheap; int heap_id; myallocator = dmm_init(); heap_id = map_thread_heap(); printf("This thread accesses heap %d\n", heap_id); myheap = &myallocator->heaps[heap_id]; }