|
@@ -9,7 +9,7 @@
|
|
|
|
|
|
void * custom_malloc(heap_t* heap, size_t size) {
|
|
void * custom_malloc(heap_t* heap, size_t size) {
|
|
void *ptr;
|
|
void *ptr;
|
|
- int fixed_list_id, i, found;
|
|
|
|
|
|
+ int fixed_list_id, i;
|
|
maptable_node_t *current_maptable_node;
|
|
maptable_node_t *current_maptable_node;
|
|
void *current_block, *previous_block;
|
|
void *current_block, *previous_block;
|
|
|
|
|
|
@@ -34,52 +34,36 @@ void * custom_malloc(heap_t* heap, size_t size) {
|
|
if(current_maptable_node->fixed_list_head != NULL) {
|
|
if(current_maptable_node->fixed_list_head != NULL) {
|
|
ptr = current_maptable_node->fixed_list_head;
|
|
ptr = current_maptable_node->fixed_list_head;
|
|
current_maptable_node->fixed_list_head = get_next(ptr);
|
|
current_maptable_node->fixed_list_head = get_next(ptr);
|
|
- set_requested_size(ptr, size);
|
|
|
|
- set_next(ptr, heap->used_blocks_head);
|
|
|
|
- heap->used_blocks_head = ptr;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if(ptr == NULL) {
|
|
if(ptr == NULL) {
|
|
- found = 0;
|
|
|
|
|
|
|
|
// first fit from free list
|
|
// first fit from free list
|
|
for(current_block = heap->free_list_head; current_block != NULL;
|
|
for(current_block = heap->free_list_head; current_block != NULL;
|
|
current_block = get_next(current_block)) {
|
|
current_block = get_next(current_block)) {
|
|
if(get_size(current_block) >= size) {
|
|
if(get_size(current_block) >= size) {
|
|
- ptr = current_block;
|
|
|
|
- heap->used_blocks_head = ptr;
|
|
|
|
- if(current_block != heap->free_list_head) {
|
|
|
|
- set_next(previous_block, get_next(ptr));
|
|
|
|
- } else {
|
|
|
|
|
|
+ if(current_block == heap->free_list_head) {
|
|
heap->free_list_head = get_next(ptr);
|
|
heap->free_list_head = get_next(ptr);
|
|
|
|
+ } else {
|
|
|
|
+ set_next(previous_block, get_next(current_block));
|
|
}
|
|
}
|
|
- set_requested_size(ptr, size);
|
|
|
|
- set_next(ptr, heap->used_blocks_head);
|
|
|
|
-
|
|
|
|
- // Begin of Stats
|
|
|
|
-
|
|
|
|
- heap->dmm_stats.live_objects += 1;
|
|
|
|
- heap->dmm_stats.num_malloc += 1;
|
|
|
|
-
|
|
|
|
- // End of Stats
|
|
|
|
-
|
|
|
|
-#ifdef HAVE_LOCKS
|
|
|
|
- posix_unlock(heap);
|
|
|
|
-#endif /* HAVE_LOCKS */
|
|
|
|
- return ptr;
|
|
|
|
|
|
+ ptr = current_block;
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
previous_block = current_block;
|
|
previous_block = current_block;
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- if(!found) {
|
|
|
|
- ptr = sys_alloc(heap, size);
|
|
|
|
- heap->dmm_stats.mem_allocated += req_padding(size);
|
|
|
|
- heap->dmm_stats.mem_requested += size;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ if(ptr == NULL) {
|
|
|
|
+ ptr = sys_alloc(heap, size);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ set_requested_size(ptr, size);
|
|
|
|
+ set_next(ptr, heap->used_blocks_head);
|
|
|
|
+
|
|
|
|
+ heap->used_blocks_head = ptr;
|
|
|
|
+
|
|
// Begin of Stats
|
|
// Begin of Stats
|
|
|
|
|
|
heap->dmm_stats.live_objects += 1;
|
|
heap->dmm_stats.live_objects += 1;
|