|
@@ -2,52 +2,48 @@
|
|
|
#include "other.h"
|
|
|
#include "split.h"
|
|
|
|
|
|
-void split(allocator_t *allocator, heap_t *heap, void *ptr) {
|
|
|
+void split(allocator_t *allocator, heap_t *heap, void *ptr,
|
|
|
+ size_t new_block_size) {
|
|
|
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;
|
|
|
-
|
|
|
-
|
|
|
- if(new_size > 0) {
|
|
|
- new_block = (void *) ((char *) ptr + get_requested_size(ptr) +
|
|
|
- HEADER_SIZE);
|
|
|
-
|
|
|
- set_size(ptr, get_requested_size(ptr));
|
|
|
-
|
|
|
- mark_used(ptr);
|
|
|
-
|
|
|
- set_size(new_block, new_size);
|
|
|
- set_previous_size_availability(new_block, get_size_availability(ptr));
|
|
|
-
|
|
|
-
|
|
|
- * Be careful, custom_free also does coalescing, we don't need that
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
+
|
|
|
+ new_block = (void *) ((char *) ptr + get_requested_size(ptr) +
|
|
|
+ HEADER_SIZE);
|
|
|
+
|
|
|
+
|
|
|
+ set_size(ptr, get_requested_size(ptr));
|
|
|
+
|
|
|
+ mark_used(ptr);
|
|
|
+
|
|
|
+ set_size(new_block, new_block_size);
|
|
|
+ set_previous_size_availability(new_block, get_size_availability(ptr));
|
|
|
+
|
|
|
+
|
|
|
+ * Be careful, custom_free also does coalescing, we don't need that
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+ fixed_list_id = map_size_to_list(heap, new_block_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 {
|
|
|
- set_next(new_block, heap->free_list_head);
|
|
|
- heap->free_list_head = new_block;
|
|
|
}
|
|
|
-
|
|
|
- mark_free(ptr);
|
|
|
+ set_next(new_block, current_maptable_node->fixed_list_head);
|
|
|
+ current_maptable_node->fixed_list_head = new_block;
|
|
|
+ } else {
|
|
|
+ set_next(new_block, heap->free_list_head);
|
|
|
+ heap->free_list_head = new_block;
|
|
|
+ }
|
|
|
|
|
|
- if(allocator->border_ptr == ptr) {
|
|
|
- allocator->border_ptr = new_block;
|
|
|
- }
|
|
|
+ mark_free(ptr);
|
|
|
|
|
|
+ if(allocator->border_ptr == ptr) {
|
|
|
+ allocator->border_ptr = new_block;
|
|
|
}
|
|
|
+
|
|
|
}
|