picofuse

Default Allocator

Drop-in sys_malloc()/sys_calloc()/sys_realloc()/sys_free() wrappers around the process's allocator, or a configured default arena. More...

Collaboration diagram for Default Allocator:

Default Allocator

void * sys_malloc (size_t size)
 Allocate memory from the default allocator. More...
 
void * sys_calloc (size_t count, size_t size)
 Allocate zero-initialized memory from the default allocator. More...
 
void * sys_realloc (void *ptr, size_t size)
 Resize an allocation owned by the default allocator. More...
 
void sys_free (void *ptr)
 Release an allocation owned by the default allocator. More...
 

Detailed Description

Drop-in sys_malloc()/sys_calloc()/sys_realloc()/sys_free() wrappers around the process's allocator, or a configured default arena.

sys_malloc()/sys_calloc()/sys_realloc()/sys_free() are drop-in wrappers around the process's allocator. Until a default arena has been configured, they route straight through to the underlying system allocator (malloc() and friends). Once one is configured, they allocate from it instead, falling back to the system allocator only for a pointer the default arena doesn't own (for example, one allocated before the arena was configured).

Thread safety:

Function Documentation

◆ sys_calloc()

void* sys_calloc ( size_t  count,
size_t  size 
)

Allocate zero-initialized memory from the default allocator.

Parameters
countNumber of elements to allocate.
sizeSize of each element in bytes.
Returns
Pointer to the allocated block, or NULL on failure (including count * size overflowing).

◆ sys_free()

void sys_free ( void *  ptr)

Release an allocation owned by the default allocator.

Parameters
ptrAllocation to release, or NULL (a no-op).

◆ sys_malloc()

void* sys_malloc ( size_t  size)

Allocate memory from the default allocator.

Parameters
sizeNumber of bytes to allocate.
Returns
Pointer to the allocated block, or NULL on failure.

◆ sys_realloc()

void* sys_realloc ( void *  ptr,
size_t  size 
)

Resize an allocation owned by the default allocator.

Parameters
ptrExisting allocation, or NULL (behaves as sys_malloc(size)).
sizeNew size in bytes (0 behaves as sys_free(ptr), returning NULL).
Returns
Pointer to the resized allocation, or NULL on failure - in which case ptr is left valid and untouched.