BFC-Compiler
A C23 Brainfuck compiler
Loading...
Searching...
No Matches
bfc_memory.h File Reference

Checked array-allocation helpers. More...

#include <stddef.h>

Go to the source code of this file.

Macros

#define BFC_MALLOC_ARRAY(pointer, count)
 Allocates an array and infers the element size from the pointer expression.
#define BFC_CALLOC_ARRAY(pointer, count)
#define BFC_REALLOC_ARRAY(pointer, count)

Functions

void * bfc_malloc_array (size_t count, size_t element_size)
 Allocates an uninitialized array after checking count multiplication.
void * bfc_calloc_array (size_t count, size_t element_size)
 Allocates a zero-initialized array after checking count multiplication.
void * bfc_realloc_array (void *allocation, size_t count, size_t element_size)
 Resizes a typed array after checking count multiplication.

Detailed Description

Checked array-allocation helpers.

Provides overflow-checked allocation functions for typed arrays and convenience macros that infer element size from pointer type.

Macro Definition Documentation

◆ BFC_CALLOC_ARRAY

#define BFC_CALLOC_ARRAY ( pointer,
count )
Value:
bfc_calloc_array((count), sizeof(*(pointer)))
void * bfc_calloc_array(size_t count, size_t element_size)
Allocates a zero-initialized array after checking count multiplication.
Definition bfc_memory.c:31

◆ BFC_MALLOC_ARRAY

#define BFC_MALLOC_ARRAY ( pointer,
count )
Value:
bfc_malloc_array((count), sizeof(*(pointer)))
void * bfc_malloc_array(size_t count, size_t element_size)
Allocates an uninitialized array after checking count multiplication.
Definition bfc_memory.c:16

Allocates an array and infers the element size from the pointer expression.

◆ BFC_REALLOC_ARRAY

#define BFC_REALLOC_ARRAY ( pointer,
count )
Value:
bfc_realloc_array((pointer), (count), sizeof(*(pointer)))
void * bfc_realloc_array(void *allocation, size_t count, size_t element_size)
Resizes a typed array after checking count multiplication.
Definition bfc_memory.c:46

Function Documentation

◆ bfc_calloc_array()

void * bfc_calloc_array ( size_t count,
size_t element_size )

Allocates a zero-initialized array after checking count multiplication.

Allocates a zero-filled typed array after checked size multiplication.

Parameters
[in]countNumber of elements.
[in]element_sizeSize of each element in bytes.
Returns
A zero-initialized block, or nullptr on overflow or allocation failure.
Note
The returned allocation must be released with free().

Allocates a zero-initialized array after checking count multiplication.

◆ bfc_malloc_array()

void * bfc_malloc_array ( size_t count,
size_t element_size )

Allocates an uninitialized array after checking count multiplication.

Allocates an uninitialized typed array after checked size multiplication.

Parameters
[in]countNumber of elements.
[in]element_sizeSize of each element in bytes.
Returns
A newly allocated block, or nullptr on overflow or allocation failure.
Note
The returned allocation must be released with free().

Allocates an uninitialized array after checking count multiplication.

◆ bfc_realloc_array()

void * bfc_realloc_array ( void * allocation,
size_t count,
size_t element_size )

Resizes a typed array after checking count multiplication.

Resizes a typed array after checked size multiplication.

Parameters
[in,out]allocationExisting allocation, or nullptr.
[in]countRequested number of elements.
[in]element_sizeSize of each element in bytes.
Returns
The resized block, or nullptr on overflow or allocation failure.
Note
On failure, the original allocation remains valid.

Resizes a typed array after checking count multiplication.