19 void* alloc = malloc(
size);
24 DC_ASSERT(alloc != NULL,
"Standard allocator failed to malloc");
30 void* alloc = calloc(
size, 1);
37 DC_ASSERT(alloc != NULL,
"Standard allocator failed to calloc");
43 DC_ASSERT(new_size > 0,
"Cannot allocate zero sized");
44 DC_ASSERT(ptr,
"Cannot reallocate a null pointer");
45 DC_ASSUME(old_size > 0,
"Could never have allocated zero sized");
47 if (new_size < old_size) {
54 (
char const*)ptr + new_size, old_size - new_size);
57 void* new_ptr = realloc(ptr, new_size);
58 DC_ASSERT(new_ptr != NULL,
"Standard allocator failed to realloc");
60 if (new_size > old_size) {
62 (
char*)new_ptr + old_size, new_size - old_size);
95 fprintf(
stream,
"stdalloc@%p { }", (
void*)self);
static DC_PUBLIC void deallocate(SELF *self, void *ptr, size_t size)
static DC_PUBLIC void debug(SELF const *self, dc_debug_fmt fmt, FILE *stream)
static DC_PUBLIC void * allocate_zeroed(SELF *self, size_t size)
static DC_PUBLIC void * allocate_uninit(SELF *self, size_t size)
static DC_PUBLIC void * reallocate(SELF *self, void *ptr, size_t old_size, size_t new_size)
#define DC_TRAIT_ALLOC(SELF)
static DC_PUBLIC size_t size(SELF const *self)
static DC_PUBLIC void dc_memory_tracker_set(dc_memory_tracker_level level, dc_memory_tracker_capability cap, const volatile void *addr, size_t size)
@ DC_MEMORY_TRACKER_LVL_ALLOC
@ DC_MEMORY_TRACKER_CAP_WRITE
@ DC_MEMORY_TRACKER_CAP_READ_WRITE
#define DC_ASSERT(expr,...)
#define DC_ASSUME(expr,...)
#define DC_TRAIT_REFERENCABLE_SINGLETON(SELF, INSTANCE)
static stdalloc stdalloc_instance
Debug format helpers for debug printin data structures.
static DC_PUBLIC FILE * stream(SELF *self)
#define DC_ZERO_SIZED(TYPE)
Zero sized types are useful as markers (e.g. for gdb printing, or to replace debug info structs.