|
@@ -0,0 +1,53 @@
|
|
|
+#include "block_header.h"
|
|
|
+#include "other.h"
|
|
|
+#include "split.h"
|
|
|
+
|
|
|
+void split(allocator_t *allocator, heap_t *heap, void *ptr) {
|
|
|
+ void *new_block;
|
|
|
+ size_t new_size;
|
|
|
+ int fixed_list_id, i;
|
|
|
+ maptable_node_t *current_maptable_node;
|
|
|
+
|
|
|
+ new_size = get_size(ptr) - get_requested_size(ptr) - HEADER_SIZE;
|
|
|
+
|
|
|
+ /* FIXME This check should be done one level above */
|
|
|
+ if(new_size > 0) {
|
|
|
+ new_block = (void *) ((char *) ptr + get_requested_size(ptr) +
|
|
|
+ HEADER_SIZE);
|
|
|
+
|
|
|
+ set_size(ptr, get_requested_size(ptr));
|
|
|
+ /* set_size() resets the availability of the block */
|
|
|
+ mark_used(ptr);
|
|
|
+
|
|
|
+ set_size(new_block, new_size);
|
|
|
+ set_previous_size_availability(new_block, get_size_availability(ptr));
|
|
|
+
|
|
|
+ /* FIXME code from custom_free, some refactoring maybe?
|
|
|
+ * Be careful, custom_free also does coalescing, we don't need that
|
|
|
+ */
|
|
|
+
|
|
|
+ /* Check if the block could be put in a fixed list */
|
|
|
+ fixed_list_id = map_size_to_list(heap, new_size);
|
|
|
+
|
|
|
+ if(fixed_list_id != -1) {
|
|
|
+ current_maptable_node = heap->maptable_head;
|
|
|
+ if(fixed_list_id != 0) {
|
|
|
+ for(i = 1; i < fixed_list_id; i++) {
|
|
|
+ current_maptable_node = current_maptable_node->next;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ set_next(new_block, current_maptable_node->fixed_list_head);
|
|
|
+ current_maptable_node->fixed_list_head = new_block;
|
|
|
+ } else { /* put it in the free list */
|
|
|
+ set_next(new_block, heap->free_list_head);
|
|
|
+ heap->free_list_head = new_block;
|
|
|
+ }
|
|
|
+
|
|
|
+ mark_free(ptr);
|
|
|
+
|
|
|
+ if(allocator->border_ptr == ptr) {
|
|
|
+ allocator->border_ptr = new_block;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|