MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_vmem_alloc

Function cbm_vmem_alloc

src/foundation/vmem.c:130–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130void *cbm_vmem_alloc(size_t size) {
131 if (size == 0) {
132 return NULL;
133 }
134
135 size_t alloc_size = round_to_page(size);
136
137#ifdef _WIN32
138 void *ptr = VirtualAlloc(NULL, alloc_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
139#else
140 void *ptr = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
141 if (ptr == MAP_FAILED) {
142 ptr = NULL;
143 }
144#endif
145
146 if (!ptr) {
147 cbm_log_error("vmem.alloc.fail", "size_mb", size > MB_DIVISOR ? "large" : "small");
148 return NULL;
149 }
150
151 size_t new_total = atomic_fetch_add(&g_allocated, alloc_size) + alloc_size;
152 update_peak(new_total);
153 check_pressure(new_total);
154
155 return ptr;
156}
157
158void cbm_vmem_free(void *ptr, size_t size) {
159 if (!ptr || size == 0) {

Callers 1

test_vmem.cFile · 0.85

Calls 3

round_to_pageFunction · 0.85
update_peakFunction · 0.85
check_pressureFunction · 0.70

Tested by

no test coverage detected