Drop-in sys_malloc()/sys_calloc()/sys_realloc()/sys_free() wrappers around the process's allocator, or a configured default arena.
More...
|
| 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...
|
| |
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:
- Safe to call concurrently from multiple threads or cores, same as the underlying system allocator and sys_mem_arena_t.
◆ sys_calloc()
| void* sys_calloc |
( |
size_t |
count, |
|
|
size_t |
size |
|
) |
| |
Allocate zero-initialized memory from the default allocator.
- Parameters
-
| count | Number of elements to allocate. |
| size | Size 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
-
| ptr | Allocation to release, or NULL (a no-op). |
◆ sys_malloc()
| void* sys_malloc |
( |
size_t |
size | ) |
|
Allocate memory from the default allocator.
- Parameters
-
| size | Number 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
-
| ptr | Existing allocation, or NULL (behaves as sys_malloc(size)). |
| size | New 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.