KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
Loading...
Searching...
No Matches
Data Structures | Functions
allocator.h File Reference
#include <stddef.h>
Include dependency graph for allocator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  KlAllocator
 Bring-your-own allocator vtable. More...
 

Functions

KlAllocator kl_allocator_default (void)
 Return the default stdlib-backed allocator.
 
void * kl_malloc (KlAllocator *a, size_t size)
 Allocate memory through the given allocator.
 
void * kl_realloc (KlAllocator *a, void *ptr, size_t old_size, size_t new_size)
 Reallocate memory through the given allocator.
 
void kl_free (KlAllocator *a, void *ptr, size_t size)
 Free memory through the given allocator.
 

Function Documentation

◆ kl_allocator_default()

KlAllocator kl_allocator_default ( void  )

Return the default stdlib-backed allocator.

Returns
Allocator wrapping malloc/realloc/free.

◆ kl_malloc()

void * kl_malloc ( KlAllocator a,
size_t  size 
)

Allocate memory through the given allocator.

Parameters
aAllocator to use.
sizeBytes to allocate.
Returns
Pointer to allocated memory, or NULL on failure.

◆ kl_realloc()

void * kl_realloc ( KlAllocator a,
void *  ptr,
size_t  old_size,
size_t  new_size 
)

Reallocate memory through the given allocator.

Parameters
aAllocator to use.
ptrExisting allocation (may be NULL).
old_sizePrevious allocation size.
new_sizeDesired new size.
Returns
Pointer to reallocated memory, or NULL on failure.

◆ kl_free()

void kl_free ( KlAllocator a,
void *  ptr,
size_t  size 
)

Free memory through the given allocator.

Parameters
aAllocator to use.
ptrPointer to free.
sizeSize of the allocation being freed.