MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / test_memory_allocator_struct

Function test_memory_allocator_struct

scripts/test_stringzilla.cpp:209–236  ·  view source on GitHub ↗

@brief Validates `sz_memory_allocator_t` and related construction utilities. */

Source from the content-addressed store, hash-verified

207
208/** @brief Validates `sz_memory_allocator_t` and related construction utilities. */
209void test_memory_allocator_struct() {
210 // Our behavior for `malloc(0)` is to return a NULL pointer,
211 // while the standard is implementation-defined.
212 {
213 sz_memory_allocator_t alloc;
214 sz_memory_allocator_init_default(&alloc);
215 assert(alloc.allocate(0, alloc.handle) == nullptr);
216 }
217
218 // Non-NULL allocation
219 {
220 sz_memory_allocator_t alloc;
221 sz_memory_allocator_init_default(&alloc);
222 void *byte = alloc.allocate(1, alloc.handle);
223 assert(byte != nullptr);
224 alloc.free(byte, 1, alloc.handle);
225 }
226
227 // Use a fixed buffer
228 {
229 char buffer[1024];
230 sz_memory_allocator_t alloc;
231 sz_memory_allocator_init_fixed(&alloc, buffer, sizeof(buffer));
232 void *byte = alloc.allocate(1, alloc.handle);
233 assert(byte != nullptr);
234 alloc.free(byte, 1, alloc.handle);
235 }
236}
237
238/** @brief Validates `sz_byteset_t` and related construction utilities. */
239void test_byteset_struct() {

Callers 1

mainFunction · 0.85

Calls 3

allocateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…