libclap 1.0.0
Command Line Argument Parser for C
Loading...
Searching...
No Matches
Functions
clap_allocator.h File Reference

Custom memory allocator support. More...

#include <stddef.h>
#include <clap/clap_export.h>
Include dependency graph for clap_allocator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

CLAP_EXPORT void clap_set_allocator (void *(*malloc_fn)(size_t), void(*free_fn)(void *), void *(*realloc_fn)(void *, size_t))
 Set custom memory allocator functions.
 

Detailed Description

Custom memory allocator support.

Function Documentation

◆ clap_set_allocator()

CLAP_EXPORT void clap_set_allocator ( void *(*)(size_t)  malloc_fn,
void(*)(void *)  free_fn,
void *(*)(void *, size_t)  realloc_fn 
)

Set custom memory allocator functions.

All subsequent allocations (internal buffers, namespace entries, etc.) use these callbacks. Must be called before any other libclap function — once parsing begins the allocator is locked in.

Parameters
malloc_fnAllocation callback, must match malloc() semantics. Must not be NULL.
free_fnDeallocation callback, must match free() semantics. Must not be NULL.
realloc_fnReallocation callback, must match realloc() semantics. Pass NULL if not needed (libclap falls back to malloc+copy+free internally).
Note
This function must be called before any parser is created. Calling it after clap_parser_new() has undefined behavior.