7#if !defined(SKIP_INCLUDES)
15 #if !defined DC_PLACEHOLDERS
34 void* buffer_start = &(*self->buffer)[0];
35 void* buffer_end = &(*self->buffer)[
CAPACITY];
36 return buffer_start <= ptr && ptr < buffer_end;
42 .alloc_ref = alloc_ref,
43 .head_ptr = &(*buffer)[0],
44 .last_alloc_ptr = NULL,
45 .derive_c_hybridstaticalloc = {},
60 char* buffer_end = &(*self->buffer)[
CAPACITY];
61 if (self->head_ptr +
size > buffer_end) {
65 char* allocation_ptr = self->head_ptr;
72 memset(allocation_ptr, 0,
size);
74 self->last_alloc_ptr = allocation_ptr;
75 self->head_ptr +=
size;
79 allocation_ptr,
size);
81 return allocation_ptr;
86 if (allocation_ptr == NULL) {
89 return allocation_ptr;
96 char* buffer_end = &(*self->buffer)[
CAPACITY];
97 if (self->head_ptr +
size > buffer_end) {
101 char* allocation_ptr = self->head_ptr;
103 self->last_alloc_ptr = allocation_ptr;
104 self->head_ptr +=
size;
109 return allocation_ptr;
118 if (statically_allocated == NULL) {
122 return statically_allocated;
129 char* byte_ptr = (
char*)ptr;
132 if (byte_ptr == self->last_alloc_ptr) {
134 self->head_ptr = byte_ptr;
135 self->last_alloc_ptr = NULL;
155 char* byte_ptr = (
char*)ptr;
157 if (new_size == old_size) {
162 if (byte_ptr == self->last_alloc_ptr) {
163 char* buffer_end = &(*self->buffer)[
CAPACITY];
165 if (new_size > old_size) {
167 size_t increase = new_size - old_size;
168 if (self->head_ptr + increase <= buffer_end) {
170 self->head_ptr, increase);
171 self->head_ptr += increase;
176 size_t decrease = old_size - new_size;
178 byte_ptr + new_size, decrease);
179 self->head_ptr -= decrease;
182 }
else if (new_size < old_size) {
185 byte_ptr + new_size, old_size - new_size);
191 memcpy(new_buff, ptr, old_size < new_size ? old_size : new_size);
200 DC_ASSERT(new_size > 0,
"Cannot allocate zero sized");
231 size_t used = (size_t)(self->head_ptr - &(*self->buffer)[0]);
234 &(*self->buffer)[0], used);
237 self->head_ptr = &(*self->buffer)[0];
238 self->last_alloc_ptr = NULL;
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 reset(SELF *self)
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)
static DC_PUBLIC void PRIV static_deallocate(SELF *self, void *ptr, size_t size)
#define CAPACITY
A hybrid of a bump allocator on a statically allocated buffer, and any other allocator.
static DC_PUBLIC void *PRIV static_reallocate(SELF *self, void *ptr, size_t old_size, size_t new_size)
static DC_PUBLIC void *PRIV static_allocate_zeroed(SELF *self, size_t size)
static DC_INTERNAL bool PRIV contains_ptr(SELF const *self, void *ptr)
static DC_PUBLIC void *PRIV static_allocate_uninit(SELF *self, size_t size)
#define DC_TRAIT_ALLOC(SELF)
static DC_PUBLIC size_t size(SELF const *self)
#define TEMPLATE_ERROR(...)
With the user provided name, even in nested templates.
static DC_PUBLIC void dc_debug_fmt_print(dc_debug_fmt fmt, FILE *stream, const char *format,...)
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_end(dc_debug_fmt fmt)
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_begin(dc_debug_fmt fmt)
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_NONE
@ DC_MEMORY_TRACKER_CAP_READ_WRITE
#define DC_EXPAND_STRING(NAME)
#define DC_ASSERT(expr,...)
#define DC_ASSUME(expr,...)
#define DC_TRAIT_REFERENCABLE_BY_PTR(SELF)
An allocator that prints to stdout when it allocates or frees memory.
dc_gdb_marker derive_c_hybridstaticalloc
Debug format helpers for debug printin data structures.
static DC_PUBLIC FILE * stream(SELF *self)