Просмотр исходного кода

Got rid of requested_size in case we don't need it.

Ioannis Koutras лет назад: 13
Родитель
Сommit
d4a491cd35
7 измененных файлов с 40 добавлено и 10 удалено
  1. 6 0
      private-include/block_header.h
  2. 16 1
      private-include/split.h
  3. 4 0
      src/block_header.c
  4. 2 0
      src/custom_free.c
  5. 4 3
      src/custom_malloc.c
  6. 6 5
      src/split.c
  7. 2 1
      src/sys_alloc.c

+ 6 - 0
private-include/block_header.h

@@ -38,7 +38,9 @@ typedef struct block_header_s {
     size_t size; /**< The LSB represents the availability of the block (1
     size_t size; /**< The LSB represents the availability of the block (1
                    for used, 0 for free), the rest the size of the data
                    for used, 0 for free), the rest the size of the data
                    part. */
                    part. */
+#ifdef FUTURE_FEATURES
     size_t requested_size; /**< The requested size of the data part */
     size_t requested_size; /**< The requested size of the data part */
+#endif /* FUTURE_FEATURES */
     size_t previous_size; /**< The LSB represents the availability of the
     size_t previous_size; /**< The LSB represents the availability of the
                             previous block, the rest the size of the data
                             previous block, the rest the size of the data
                             part of the previous block in the memory space */
                             part of the previous block in the memory space */
@@ -71,6 +73,7 @@ block_header_t * get_header(void *ptr);
  */
  */
 size_t get_size(void *ptr);
 size_t get_size(void *ptr);
 
 
+#ifdef FUTURE_FEATURES
 /**
 /**
  * Get the requested size of the memory block's data
  * Get the requested size of the memory block's data
  *
  *
@@ -80,6 +83,7 @@ size_t get_size(void *ptr);
  * block.
  * block.
  */
  */
 size_t get_requested_size(void *ptr);
 size_t get_requested_size(void *ptr);
+#endif /* FUTURE_FEATURES */
 
 
 /**
 /**
  * Get all information of the memory block header's size record
  * Get all information of the memory block header's size record
@@ -107,6 +111,7 @@ void set_size_and_free(void *ptr, size_t size);
  */
  */
 void set_size_and_used(void *ptr, size_t size);
 void set_size_and_used(void *ptr, size_t size);
 
 
+#ifdef FUTURE_FEATURES
 /**
 /**
  * Set the requested size of memory block's data
  * Set the requested size of memory block's data
  *
  *
@@ -115,6 +120,7 @@ void set_size_and_used(void *ptr, size_t size);
  * block.
  * block.
  */
  */
 void set_requested_size(void *ptr, size_t size);
 void set_requested_size(void *ptr, size_t size);
+#endif /* FUTURE_FEATURES */
 
 
 /**
 /**
  * Mark the memory block as used
  * Mark the memory block as used

+ 16 - 1
private-include/split.h

@@ -15,7 +15,22 @@
  *
  *
  */
  */
 
 
+#ifndef SPLIT_H
+#define SPLIT_H
+
 #include <dmmlib/heap.h>
 #include <dmmlib/heap.h>
 
 
+/**
+ * Splits a memory block to two blocks: one with the requested size and the
+ * another one with the remaining space.
+ *
+ * @param allocator The involved allocator.
+ * @param heap The heap of the memory block.
+ * @param ptr The memory block to be split.
+ * @param req_size The size which the first block will use.
+ */ 
 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);
+		size_t req_size);
+
+#endif /* SPLIT_H */
+

+ 4 - 0
src/block_header.c

@@ -25,9 +25,11 @@ size_t get_size(void *ptr) {
     return get_header(ptr)->size >> 1;
     return get_header(ptr)->size >> 1;
 }
 }
 
 
+#ifdef FUTURE_FEATURES
 size_t get_requested_size(void *ptr) {
 size_t get_requested_size(void *ptr) {
     return get_header(ptr)->requested_size;
     return get_header(ptr)->requested_size;
 }
 }
+#endif /* FUTURE_FEATURES */
 
 
 size_t get_size_availability(void *ptr) {
 size_t get_size_availability(void *ptr) {
     return get_header(ptr)->size;
     return get_header(ptr)->size;
@@ -43,9 +45,11 @@ void set_size_and_used(void *ptr, size_t size) {
     header->size |= 1;
     header->size |= 1;
 }
 }
 
 
+#ifdef FUTURE_FEATURES
 void set_requested_size(void *ptr, size_t size) {
 void set_requested_size(void *ptr, size_t size) {
     get_header(ptr)->requested_size = size;
     get_header(ptr)->requested_size = size;
 }
 }
+#endif /* FUTURE_FEATURES */
 
 
 void mark_used(void *ptr) {
 void mark_used(void *ptr) {
     get_header(ptr)->size |= 1;
     get_header(ptr)->size |= 1;

+ 2 - 0
src/custom_free.c

@@ -62,7 +62,9 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
 
 
 #ifdef WITH_STATS
 #ifdef WITH_STATS
     heap->dmm_stats.mem_allocated -= size;
     heap->dmm_stats.mem_allocated -= size;
+#ifdef FUTURE_FEATURES
     heap->dmm_stats.mem_requested -= get_requested_size(ptr);
     heap->dmm_stats.mem_requested -= get_requested_size(ptr);
+#endif /* FUTURE_FEATURES */
 #endif /* WITH_STATS */
 #endif /* WITH_STATS */
 
 
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)

+ 4 - 3
src/custom_malloc.c

@@ -78,12 +78,13 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
 
 
     if(ptr != NULL) {
     if(ptr != NULL) {
 
 
-        /* FIXME To be refactored - START */
+#ifdef FUTURE_FEATURES
         set_requested_size(ptr, size);
         set_requested_size(ptr, size);
+#endif /* FUTURE_FEATURES */
 
 
         /* Try to split */
         /* Try to split */
 #if defined (SPLITTING_FIXED) || defined (SPLITTING_VARIABLE)
 #if defined (SPLITTING_FIXED) || defined (SPLITTING_VARIABLE)
-        new_size = get_size(ptr) - get_requested_size(ptr) - HEADER_SIZE;
+        new_size = get_size(ptr) - size - HEADER_SIZE;
 
 
 #ifdef SPLITTING_FIXED
 #ifdef SPLITTING_FIXED
         min_split_size = MIN_SPLITTING_SIZE;
         min_split_size = MIN_SPLITTING_SIZE;
@@ -93,7 +94,7 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
 #endif /* SPLITTING_VARIABLE */
 #endif /* SPLITTING_VARIABLE */
 
 
         if(new_size > min_split_size) {
         if(new_size > min_split_size) {
-            split(allocator, heap, ptr, new_size);
+            split(allocator, heap, ptr, size);
         } else {
         } else {
             mark_used(ptr);
             mark_used(ptr);
         }
         }

+ 6 - 5
src/split.c

@@ -21,16 +21,17 @@
 #include "dmm_config.h"
 #include "dmm_config.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) {
+        size_t req_size) {
     void *new_block;
     void *new_block;
     int fixed_list_id, i;
     int fixed_list_id, i;
+    size_t new_block_size;
     maptable_node_t *current_maptable_node;
     maptable_node_t *current_maptable_node;
 
 
-    new_block = (void *) ((char *) ptr + get_requested_size(ptr) + 
-            HEADER_SIZE);
+    new_block = (void *) ((char *) ptr + req_size + HEADER_SIZE);
+    new_block_size = get_size(ptr) - req_size - HEADER_SIZE;
 
 
-    /* Resize the previous, used block */
-    set_size_and_used(ptr, get_requested_size(ptr));
+    /* Resize the previous, to be used block */
+    set_size_and_used(ptr, req_size);
 
 
     set_size_and_free(new_block, new_block_size);
     set_size_and_free(new_block, new_block_size);
     set_previous_size_availability(new_block, get_size_availability(ptr));
     set_previous_size_availability(new_block, get_size_availability(ptr));

+ 2 - 1
src/sys_alloc.c

@@ -108,8 +108,9 @@ void *sys_alloc(allocator_t *allocator, heap_t *heap, size_t size) {
     set_size_and_used(ptr, req_padding(size));
     set_size_and_used(ptr, req_padding(size));
     set_previous_size_availability(ptr, previous_size_availability);
     set_previous_size_availability(ptr, previous_size_availability);
 
 
-    /* FIXME To be refactored - START */
+#ifdef FUTURE_FEATURES
     set_requested_size(ptr, size);
     set_requested_size(ptr, size);
+#endif /* FUTURE_FEATURES */
 
 
     /* Update the used blocks list */
     /* Update the used blocks list */
     push_block(ptr, heap->used_blocks_head);
     push_block(ptr, heap->used_blocks_head);