squareball  0.2.0.52-e4ea
A general-purpose library for C99
sb-mem.h File Reference

Memory allocation related helpers. More...

#include <stddef.h>

Go to the source code of this file.

typedef void(* sb_free_func_t) (void *ptr)
 
void * sb_malloc (size_t size)
 
void * sb_realloc (void *ptr, size_t size)
 

Detailed Description

Memory allocation related helpers.

Typedef Documentation

typedef void(* sb_free_func_t) (void *ptr)

Function signature for helpers that are used to free memory of custom types.

Each function should receive the pointer, and free the memory used by the type as needed.

The sb_slist_free_full function is an example of usage of these helper functions.

Parameters
ptrAn dinamically allocated pointer to be free'd.

Function Documentation

void* sb_malloc ( size_t  size)

Safe malloc replacement function. This function validates the output of the libc's malloc call and aborts if needed. See malloc(3) for details.

Parameters
sizeNumber of bytes to be allocated.
Returns
A pointer to the allocated memory.
Examples:
hello_custom_error_type.c.
void* sb_realloc ( void *  ptr,
size_t  size 
)

Safe realloc replacement function. This function validates the output of the libc's realloc call and aborts if needed. See realloc(3) for details.

Parameters
ptrA pointer to be resized.
sizeNew number of bytes allocated after reallocation.
Returns
A pointer to the reallocated memory.