8 #define MAGIC "DEADBEEF"
72 alloc->
base = rawbase;
100 memset(alloc->
base, 0, alloc->
size);
108 size_t size = request_size;
121 endrun(1,
"Not enough memory for %s %td bytes\n",
name, size);
129 endrun(1,
"Not enough memory for %s %td bytes\n",
name, size);
131 ptr = alloc->
base + alloc->
top - size;
147 header->
name[126] =
'\0';
228 endrun(5,
"Ptr %p is not a magic header\n", header);
250 return 2L*1024L*1024L*1024L;
286 message(1,
"--------------- Allocator: %-17s %12s-----------------\n",
291 message(1,
" Free: %010td Used: %010td Top: %010td Bottom: %010td \n",
298 message(1,
" %-20s | %c | %-12s %-12s | %s\n",
"Name",
'd',
"Requested",
"Allocated",
"Annotation");
299 message(1,
"-------------------------------------------------------\n");
304 message(1,
" %-20s | %c | %012td %012td | %s\n",
306 "T?B"[iter->
dir + 1],
317 char * cptr = (
char *)
ptr;
323 endrun(1,
"Not an allocated address: Header = %08p ptr = %08p\n", header, cptr);
333 memcpy(header2->
self, header2,
sizeof(header2[0]));
351 memmove(newptr, tmp.
ptr, tmp.
size);
360 char * cptr = (
char *)
ptr;
365 endrun(1,
"Not an allocated address: Header = %08p ptr = %08p\n", header, cptr);
378 char * cptr = (
char *)
ptr;
409 header->
alloc = NULL;
void message(int where, const char *fmt,...)
void endrun(int where, const char *fmt,...)
static int is_header(struct BlockHeader *header)
void * allocator_alloc(Allocator *alloc, const char *name, const size_t request_size, const int dir, const char *fmt,...)
int allocator_iter_next(AllocatorIter *iter)
int allocator_init(Allocator *alloc, const char *name, const size_t request_size, const int zero, Allocator *parent)
void allocator_free(void *ptr)
int allocator_malloc_init(Allocator *alloc, const char *name, const size_t request_size, const int zero, Allocator *parent)
int allocator_reset(Allocator *alloc, int zero)
size_t allocator_get_free_size(Allocator *alloc)
static void * allocator_alloc_va(Allocator *alloc, const char *name, const size_t request_size, const int dir, const char *fmt, va_list va)
int allocator_dealloc(Allocator *alloc, void *ptr)
void * allocator_realloc_int(Allocator *alloc, void *ptr, const size_t new_size, const char *fmt,...)
void allocator_print(Allocator *alloc)
int allocator_iter_start(AllocatorIter *iter, Allocator *alloc)
int allocator_destroy(Allocator *alloc)
size_t allocator_get_used_size(Allocator *alloc, int dir)
int allocator_iter_ended(AllocatorIter *iter)