|
@@ -7,15 +7,20 @@
|
|
|
#ifdef WITH_COALESCING
|
|
|
#include "coalesce.h"
|
|
|
#endif
|
|
|
+#include "dmm_adaptor.h"
|
|
|
#include "block_header.h"
|
|
|
|
|
|
void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
|
|
|
size_t size;
|
|
|
int heap_id, fixed_list_id, i;
|
|
|
maptable_node_t *current_maptable_node;
|
|
|
+#ifdef WITH_COALESCING
|
|
|
+ void *coalesced_ptr;
|
|
|
+ bool coalesced;
|
|
|
+#endif
|
|
|
|
|
|
#ifndef WITH_MEMORY_SPACE_AWARENESS
|
|
|
-
|
|
|
+
|
|
|
if(allocator == NULL) {
|
|
|
allocator = &systemallocator;
|
|
|
}
|
|
@@ -35,39 +40,58 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
|
|
|
remove_block(ptr, heap->used_blocks_head);
|
|
|
|
|
|
#ifdef WITH_COALESCING
|
|
|
- ptr = coalesce(ptr, heap);
|
|
|
+ coalesced_ptr = coalesce(ptr, heap, allocator);
|
|
|
+ if(coalesced_ptr != ptr) {
|
|
|
+ ptr = coalesced_ptr;
|
|
|
+ coalesced = true;
|
|
|
+ } else {
|
|
|
+ coalesced = false;
|
|
|
+ }
|
|
|
#endif
|
|
|
|
|
|
-
|
|
|
+
|
|
|
fixed_list_id = map_size_to_list(heap, size);
|
|
|
|
|
|
if(fixed_list_id != -1) {
|
|
|
current_maptable_node = heap->maptable_head;
|
|
|
- if(fixed_list_id == 0) {
|
|
|
- set_next(ptr, current_maptable_node->fixed_list_head);
|
|
|
- current_maptable_node->fixed_list_head = ptr;
|
|
|
- } else {
|
|
|
+ if(fixed_list_id != 0) {
|
|
|
for(i = 1; i < fixed_list_id; i++) {
|
|
|
current_maptable_node = current_maptable_node->next;
|
|
|
}
|
|
|
- set_next(ptr, current_maptable_node->fixed_list_head);
|
|
|
- current_maptable_node->fixed_list_head = ptr;
|
|
|
}
|
|
|
- } else {
|
|
|
+ set_next(ptr, current_maptable_node->fixed_list_head);
|
|
|
+ current_maptable_node->fixed_list_head = ptr;
|
|
|
+ } else {
|
|
|
+#ifdef WITH_COALESCING
|
|
|
+
|
|
|
+ * list as there is already an entry of the old block
|
|
|
+ */
|
|
|
+ if(!coalesced) {
|
|
|
+ set_next(ptr, heap->free_list_head);
|
|
|
+ heap->free_list_head = ptr;
|
|
|
+ }
|
|
|
+#else
|
|
|
set_next(ptr, heap->free_list_head);
|
|
|
heap->free_list_head = ptr;
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+#ifndef WITH_COALESCING
|
|
|
+ mark_free(ptr);
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
|
|
|
heap->dmm_stats.live_objects -= 1;
|
|
|
heap->dmm_stats.num_free += 1;
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ * free's has been served already
|
|
|
+ */
|
|
|
+
|
|
|
if(heap->dmm_stats.num_free % 100) {
|
|
|
free_state_refresh(heap);
|
|
|
}
|