Browse Source

Memory-space aware allocators should also have an initialized boolean flag.

Ioannis Koutras 13 years ago
parent
commit
3bca3db049
3 changed files with 11 additions and 4 deletions
  1. 0 2
      include/dmmlib/heap.h
  2. 0 2
      src/initialize_allocator.c
  3. 11 0
      src/sys_alloc.c

+ 0 - 2
include/dmmlib/heap.h

@@ -104,9 +104,7 @@ typedef struct heap_s {
 /** The allocator structure of dmmlib. */
 typedef struct allocator_s {
 	heap_t heaps[NUM_HEAPS]; /**< The heaps that the allocator manages. */
-#ifndef WITH_MEMORY_SPACE_AWARENESS
 	bool initialized; /**< Initialization flag of the allocator. */
-#endif /* WITH_MEMORY_SPACE_AWARENESS */
 	void *border_ptr; /**< Border pointer of the allocator. */
 #ifdef WITH_MEMORY_SPACE_AWARENESS
 	size_t remaining_size; /**< The size of the remaining free space which

+ 0 - 2
src/initialize_allocator.c

@@ -145,9 +145,7 @@ void initialize_allocator(allocator_t *allocator) {
     (maptablenode+1)->fixed_list_head = NULL;
     (maptablenode+1)->next = NULL;
 
-#ifndef WITH_MEMORY_SPACE_AWARENESS
     allocator->initialized = true;
-#endif /* WITH_MEMORY_SPACE_AWARENESS */
 
 #ifdef HAVE_LOCKS
     sbrk_unlock();

+ 11 - 0
src/sys_alloc.c

@@ -40,7 +40,18 @@ void *sys_alloc(allocator_t *allocator, heap_t *heap, size_t size) {
 
     allocation_size = req_padding(size) + HEADER_SIZE;
 
+    /* Before the first application malloc() call, the allocator uses
+     * sys_alloc() to allocate space for its metadata. So, these are the first
+     * data blocks in the heaps and there are no previous data blocks.
+     */
+#ifndef WITH_MEMORY_SPACE_AWARENESS
     if(allocator->border_ptr != NULL) {
+#else
+    /* Note: border_ptr has already a value in memory space aware allocators,
+     * so in this case we have to check also the initialized value.
+     */
+    if(allocator->border_ptr != NULL && allocator->initialized) {
+#endif /* WITH_MEMORY_SPACE_AWARENESS */
         previous_size = get_size(allocator->border_ptr);
         previous_size_availability = get_size_availability(allocator->border_ptr);
     } else {