HawkTracer  0.9.0
alloc.h File Reference
#include <hawktracer/macros.h>
#include <stddef.h>

Go to the source code of this file.

Macros

#define HT_CREATE_TYPE(Type)   (Type*)ht_alloc(sizeof(Type))
 Allocates memory for a specific Type. More...
 

Functions

HT_API void ht_allocator_set (realloc_function func, void *user_data)
 Sets a global allocator for HawkTracer library. More...
 
HT_API void * ht_alloc (size_t size)
 Allocates memory using HawkTracer allocator. More...
 
HT_API void * ht_realloc (void *ptr, size_t size)
 Changes the size of the memory block. More...
 
HT_API void ht_free (void *ptr)
 Releases memory allocated by ht_alloc. More...
 

Variables

HT_DECLS_BEGIN typedef void *(* realloc_function )(void *ptr, size_t size, void *user_data)
 Callback function for a custom allocator. More...
 

Macro Definition Documentation

◆ HT_CREATE_TYPE

#define HT_CREATE_TYPE (   Type)    (Type*)ht_alloc(sizeof(Type))

Allocates memory for a specific Type.

Parameters
Typea type of an object to allocate memory for.
Returns
a pointer to allocated memory.

Function Documentation

◆ ht_alloc()

HT_API void* ht_alloc ( size_t  size)

Allocates memory using HawkTracer allocator.

Parameters
sizea number of bytes to allocate.
Returns
a pointer to allocated memory.

◆ ht_allocator_set()

HT_API void ht_allocator_set ( realloc_function  func,
void *  user_data 
)

Sets a global allocator for HawkTracer library.

The allocator is used for every allocation in the library. The function must be called before ht_init() function call. If custom allocator is not specified, default allocator will be used.

Parameters
funcan allocation function.
user_dataan opaque pointer passed to the allocator as a last argument.

◆ ht_free()

HT_API void ht_free ( void *  ptr)

Releases memory allocated by ht_alloc.

Parameters
ptra pointer to the memory block to release.

◆ ht_realloc()

HT_API void* ht_realloc ( void *  ptr,
size_t  size 
)

Changes the size of the memory block.

Parameters
ptra pointer to the memory block.
sizenew size of the memory block.
Returns
a pointer to reallocated memory.

Variable Documentation

◆ realloc_function

HT_DECLS_BEGIN typedef void*(* realloc_function) (void *ptr, size_t size, void *user_data)

Callback function for a custom allocator.

HawkTracer requires only one function, which depending on parameter values, performs: alloc, free, and realloc operations.

To allocate memory, ptr must be NULL. To free memory, size must be equal to 0. To realloc memory, size must be greater than 0, and ptr must not be NULL.

Parameters
ptra pointer to a memory block for alloc/realloc/free operations.
sizea size of memory block to allocate for alloc/realloc operations.
user_dataan user data specified in ht_allocator_set().
Returns
a pointer to allocated memory block for alloc/realloc operations.