Subastra
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Data Fields
allocator_t Struct Reference

A generic allocator type passed by value. Contains a fallback allocator and a set of function pointers for managing memory. Erases the type of the internal allocator. More...

#include <memory.h>

Public Member Functions

#define allocator_alloc_ty(ty, allocator, sz)    (ty *)allocator_alloc(allocator, sizeof(ty) * sz)
 Allocate a typed buffer of size sz using allocator.
 
#define allocator_alloc_copy_ty(ty, allocator, data, sz)    (ty *)allocator_alloc_copy(allocator, data, sizeof(ty) * sz)
 Copy sz typedef elements of data from data into a freshly allocated slice using the allocator.
 

Static Public Member Functions

static void * allocator_alloc (allocator_t allocator, sz size)
 Proxy the allocation to the actual allocator.
 
static void * allocator_alloc_copy (allocator_t allocator, const void *data, sz size)
 Copy size bytes of data from data into a freshly allocated slice using the allocator.
 
static void * allocator_realloc (allocator_t allocator, void *memory, sz size)
 Move memory to a new memory region with at least size bytes. If an allocator does not implement realloc it will be polyfilled.
 
static void allocator_free (allocator_t allocator, void *memory)
 Release memory back to the allocator.
 

Data Fields

allocator_ptr allocator
 A pointer to the actual underyling allocator, type-erased.
 
mem_alloc_falloc
 
mem_realloc_frealloc
 
mem_free_ffree
 

Detailed Description

A generic allocator type passed by value. Contains a fallback allocator and a set of function pointers for managing memory. Erases the type of the internal allocator.

Member Function Documentation

◆ allocator_alloc()

static void * allocator_alloc ( allocator_t  allocator,
sz  size 
)
inlinestatic

Proxy the allocation to the actual allocator.

◆ allocator_alloc_copy()

static void * allocator_alloc_copy ( allocator_t  allocator,
const void *  data,
sz  size 
)
inlinestatic

Copy size bytes of data from data into a freshly allocated slice using the allocator.

◆ allocator_free()

static void allocator_free ( allocator_t  allocator,
void *  memory 
)
inlinestatic

Release memory back to the allocator.

◆ allocator_realloc()

static void * allocator_realloc ( allocator_t  allocator,
void *  memory,
sz  size 
)
inlinestatic

Move memory to a new memory region with at least size bytes. If an allocator does not implement realloc it will be polyfilled.

Field Documentation

◆ alloc

mem_alloc_f* alloc

◆ allocator

allocator_ptr allocator

A pointer to the actual underyling allocator, type-erased.

◆ free

mem_free_f* free

◆ realloc

mem_realloc_f* realloc