4#if !defined(SKIP_INCLUDES)
11#if !defined BLOCK_SIZE
12 #if !defined DC_PLACEHOLDERS
15 #define BLOCK_SIZE 65536
20#define BLOCK_VECTOR NS(NAME, block_vector)
22#pragma push_macro("ALLOC")
36#define ITEM NS(NAME, block_info)
37#define ITEM_CLONE NS(NAME, block_info_clone)
38#define ITEM_DELETE NS(NAME, block_info_delete)
39#define ITEM_DEBUG NS(NAME, block_info_debug)
40#define INTERNAL_NAME BLOCK_VECTOR
43#pragma pop_macro("ALLOC")
56 .current_block_idx = 0,
57 .current_block_offset = 0,
58 .alloc_ref = alloc_ref,
59 .derive_c_chunkedbumpalloc = {},
72 for (
size_t i = 0; i < num_blocks; i++) {
73 void* block_ptr = (
char*)base_ptr + (i *
BLOCK_SIZE);
74 size_t block_count = (i == 0) ? num_blocks : 0;
83 if (self->current_block_offset == 0 &&
size > 0) {
98 size_t remaining =
BLOCK_SIZE - self->current_block_offset;
100 if (remaining >=
size) {
103 void* allocation_ptr = (
char*)current_info->ptr + self->current_block_offset;
105 self->current_block_offset +=
size;
108 allocation_ptr,
size);
110 return allocation_ptr;
122 memset(ptr, 0,
size);
141 DC_ASSERT(old_size > 0,
"Cannot reallocate zero sized");
142 DC_ASSERT(new_size > 0,
"Cannot allocate zero sized");
146 if (num_blocks > 0 && new_size > old_size) {
149 char* expected_last_alloc =
150 (
char*)current_info->ptr + self->current_block_offset - old_size;
152 if ((
char*)ptr == expected_last_alloc) {
154 size_t extension = new_size - old_size;
155 size_t remaining =
BLOCK_SIZE - self->current_block_offset;
157 if (extension <= remaining) {
160 (
char*)ptr + old_size, extension);
161 self->current_block_offset += extension;
170 size_t copy_size = (old_size < new_size) ? old_size : new_size;
171 memcpy(new_ptr, ptr, copy_size);
173 if (new_size <= old_size) {
190 for (
size_t i = 0; i < num_blocks; i++) {
192 if (info->num_blocks > 0) {
193 size_t total_size = info->num_blocks *
BLOCK_SIZE;
195 info->ptr, total_size);
201 self->current_block_idx = 0;
202 self->current_block_offset = 0;
222 size_t total_allocated = 0;
224 for (
size_t i = 0; i < num_blocks; i++) {
226 if (info->num_blocks > 0) {
227 total_allocated += info->num_blocks *
BLOCK_SIZE;
static void block_info_debug(block_info const *, dc_debug_fmt, FILE *)
static DC_PUBLIC void deallocate(SELF *self, void *ptr, size_t size)
static DC_INTERNAL void *PRIV allocate_new_blocks(SELF *self, 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 void block_info_delete(block_info *)
static DC_PUBLIC void reset(SELF *self)
static block_info block_info_clone(block_info const *self)
#define BLOCK_SIZE
A chunked bump allocator that allocates memory in fixed-size blocks.
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 VALUE const * read(SELF const *self, INDEX index)
static DC_PUBLIC size_t size(SELF const *self)
static DC_PUBLIC void remove_at(SELF *self, size_t at, size_t count)
static DC_PUBLIC ITEM * push(SELF *self, ITEM item)
#define TEMPLATE_ERROR(...)
With the user provided name, even in nested templates.
#define NAME
Supporting templates that internally invoke new 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)
dc_gdb_marker derive_c_chunkedbumpalloc
size_t current_block_offset
Debug format helpers for debug printin data structures.
static DC_PUBLIC FILE * stream(SELF *self)