|
@@ -11,7 +11,12 @@
|
|
|
#include "sys_alloc.h"
|
|
|
#include "block_header.h"
|
|
|
|
|
|
+#ifndef WITH_MEMORY_SPACE_AWARENESS
|
|
|
void *sys_alloc(heap_t *heap, size_t size) {
|
|
|
+#else
|
|
|
+void *sys_alloc(allocator_t *allocator, heap_t *heap, size_t size) {
|
|
|
+#endif
|
|
|
+
|
|
|
size_t allocation_size;
|
|
|
void *ptr;
|
|
|
|
|
@@ -21,11 +26,22 @@ void *sys_alloc(heap_t *heap, size_t size) {
|
|
|
|
|
|
allocation_size = req_padding(size) + HEADER_SIZE;
|
|
|
|
|
|
+#ifndef WITH_MEMORY_SPACE_AWARENESS
|
|
|
ptr = sbrk((int) allocation_size);
|
|
|
if(ptr == (void *) -1) {
|
|
|
printf("sbrk problem for size of: %zu\n", allocation_size);
|
|
|
printf( "Error on sbrk: %s\n", strerror( errno ) );
|
|
|
}
|
|
|
+#else
|
|
|
+ if(allocator->remaining_size >= allocation_size) {
|
|
|
+ ptr = allocator->border_ptr;
|
|
|
+ allocator->border_ptr = (char *) allocator->border_ptr + allocation_size;
|
|
|
+ allocator->remaining_size -= allocation_size;
|
|
|
+ } else {
|
|
|
+ printf("No more free space.\n");
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
ptr = (void *) ((char *) ptr + HEADER_SIZE);
|
|
|
|
|
|
set_size(ptr, req_padding(size));
|