DebugAllocatorConfig
Description
Runtime configuration for a DebugAllocator. Pass to DebugAllocatorCreateWith. Use DEBUG_ALLOCATOR_DEFAULTS for a sensible all-checks-on baseline.
Fields
| Name | Description |
|---|---|
capture_traces |
Capture a stack trace at every alloc and free site. Pays the unwinder cost on every call but gives precise leak / double-free attribution. |
detect_overflow |
Pad each user allocation with canary_bytes of sentinel bytes after the buffer; verify the pattern on free. Off-by-one writes past the user buffer are caught at the next free. |
retain_metadata |
Keep freed records in a separate map. Lets us detect double-frees on memory we’ve already given back to the parent allocator. |
trace_depth |
Number of stack frames to capture per site. Clamped to DEBUG_ALLOCATOR_MAX_TRACE. |
canary_bytes |
Trailing canary length in bytes. 0 disables. |
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Debug.c:45:
Allocator *parent;
Allocator *meta;
DebugAllocatorConfig config;
DebugRecordMap live;
DebugRecordMap freed;- In
Debug.c:274:
// ---------------------------------------------------------------------------
DebugAllocator *DebugAllocatorCreateWith(Allocator *parent, Allocator *meta_alloc, DebugAllocatorConfig config) {
if (!parent || !meta_alloc) {
LOG_ERROR("DebugAllocatorCreate: parent and meta_alloc are required");- In
Debug.h:77:
u32 trace_depth;
u32 canary_bytes;
} DebugAllocatorConfig;
#define DEBUG_ALLOCATOR_MAX_TRACE 16- In
Debug.h:82:
#define DEBUG_ALLOCATOR_DEFAULTS \
((DebugAllocatorConfig) { \
.capture_traces = true, \
.detect_overflow = true, \- In
Debug.h:113:
/// Same as `DebugAllocatorCreate` but with a custom configuration.
///
DebugAllocator *DebugAllocatorCreateWith(Allocator *parent, Allocator *meta_alloc, DebugAllocatorConfig config);
///
Last updated on