squareball 0.2.0.29-1f41 A general-purpose library for C99

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

All Data Structures Files Functions Variables Typedefs
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.

## 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

  size | Number of bytes to be allocated.

Returns
  A pointer to the allocated memory.

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

  ptr | A pointer to be resized.
  size | New number of bytes allocated after reallocation.

Returns
  A pointer to the reallocated memory.