mowgli_heap_t *const heap = allocator->allocate(sizeof *heap);
if (! heap)
- {
-#ifdef HEAP_DEBUG
- (void) mowgli_log_warning("cannot allocate memory for heap");
-#endif
return NULL;
- }
(void) memset(heap, 0x00, sizeof *heap);
heap->allocator = allocator;
heap->elem_size = elem_size;
-#ifdef HEAP_DEBUG
- (void) mowgli_log("pseudoheap@%p: created (elem_size %zu)", heap, elem_size);
-#endif
-
return heap;
}
return_if_fail(heap->allocator->deallocate != NULL);
(void) heap->allocator->deallocate(heap);
-
-#ifdef HEAP_DEBUG
- (void) mowgli_log("pseudoheap@%p: destroyed (elem_size %zu)", heap, elem_size);
-#endif
}
void *
void *ptr = heap->allocator->allocate(heap->elem_size);
if (!ptr)
- {
-#ifdef HEAP_DEBUG
- (void) mowgli_log_warning("pseudoheap@%p: cannot allocate memory for ptr", heap);
-#endif
return NULL;
- }
-
-#ifdef HEAP_DEBUG
- (void) mowgli_log("pseudoheap@%p: allocated ptr %p (elem_size %zu)", heap, block->ptr, heap->elem_size);
-#endif
return memset(ptr, 0x00, heap->elem_size);
}
return_if_fail(heap->allocator->deallocate != NULL);
return_if_fail(ptr != NULL);
-#ifdef HEAP_DEBUG
- (void) mowgli_log("pseudoheap@%p: freeing ptr %p (elem_size %zu)",
- heap, ptr, heap->elem_size);
-#endif
-
(void) heap->allocator->deallocate(ptr);
}