Loading...
Searching...
No Matches
mem.h File Reference

CYAML memory allocation handling. More...

`#include "cyaml/cyaml.h"`
Include dependency graph for mem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Functions

static void | cyaml__free (const cyaml_config_t *config, void *ptr)
static void * | cyaml__realloc (const cyaml_config_t *config, void *ptr, size_t current_size, size_t new_size, bool clean)
static void * | cyaml__alloc (const cyaml_config_t *config, size_t size, bool clean)
static char * | cyaml__strdup (const cyaml_config_t *config, const char *str, size_t *len_out)

## Detailed Description

CYAML memory allocation handling.

## Function Documentation

## cyaml__alloc()

void * cyaml__alloc | ( | const cyaml_config_t * | config,
|  | size_t | size,
|  | bool | clean )

inline static

Helper for new allocations using the client's choice of allocator routine.

Parameters

  [in] | config | The CYAML client config.
  [in] | size | The number of bytes to allocate.
  [in] | clean | If false, the memory is uninitialised, if true, the memory is initialised to zero.

Returns
  Pointer to allocation on success, or NULL on failure.

## cyaml__free()

void cyaml__free | ( | const cyaml_config_t * | config,
|  | void * | ptr )

inline static

Helper for freeing using the client's choice of allocator routine.

Parameters

  [in] | config | The CYAML client config.
  [in] | ptr | Pointer to allocation to free.

## cyaml__realloc()

void * cyaml__realloc | ( | const cyaml_config_t * | config,
|  | void * | ptr,
|  | size_t | current_size,
|  | size_t | new_size,
|  | bool | clean )

inline static

Helper for new allocations using the client's choice of allocator routine.

Note
  On failure, any existing allocation is still owned by the caller, and they are responsible for freeing it.

Parameters

  [in] | config | The CYAML client config.
  [in] | ptr | The existing allocation or NULL.
  [in] | current_size | Size of the current allocation. (Only needed if clean != false).
  [in] | new_size | The number of bytes to resize allocation to.
  [in] | clean | Only applies if new_size > current_size. If false, the new memory is uninitialised, if true, the new memory is initialised to zero.

Returns
  Pointer to allocation on success, or NULL on failure.

## cyaml__strdup()

char * cyaml__strdup | ( | const cyaml_config_t * | config,
|  | const char * | str,
|  | size_t * | len_out )

inline static

Helper for string duplication using the client's choice of allocator routine.

Parameters

  [in] | config | The CYAML client config.
  [in] | str | The string to duplicate.
  [in] | len_out | If non-NULL, updated to length of string on success.

Returns
  Pointer to new string on success, or NULL on failure.