hat-util  0.6.16
Utility library
allocator.h File Reference

Memory allocator. More...

#include <stddef.h>
Include dependency graph for allocator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  hat_allocator_t
 Allocator base struct. More...
 

Typedefs

typedef struct hat_allocator_t hat_allocator_t
 
typedef void *(* hat_allocator_realloc_t) (hat_allocator_t *a, size_t size, void *old)
 Custom allocator implementation function. More...
 

Functions

static void * hat_allocator_alloc (hat_allocator_t *a, size_t size)
 Allocate new memory block. More...
 
static void * hat_allocator_realloc (hat_allocator_t *a, size_t size, void *old)
 Reallocate existing memory block. More...
 
static void hat_allocator_free (hat_allocator_t *a, void *old)
 Free memory block. More...
 

Detailed Description

Memory allocator.

Typedef Documentation

◆ hat_allocator_realloc_t

typedef void*(* hat_allocator_realloc_t) (hat_allocator_t *a, size_t size, void *old)

Custom allocator implementation function.

Parameters
[in]aallocator instance
[in]sizenew memory block size
[in]oldprevious memory block
Returns
new memory block

Function should implement memory allocator which reallocates previously allocated memory pointed by old to newly return memory of size size. If old is NULL, then implementation allocates new memory block without resizing/copying previous. If size is set to 0, memory referenced by old is fried and NULL is returned.

◆ hat_allocator_t

Function Documentation

◆ hat_allocator_alloc()

static void* hat_allocator_alloc ( hat_allocator_t a,
size_t  size 
)
inlinestatic

Allocate new memory block.

Parameters
[in]aallocator instance
[in]sizenew memory block size
Returns
new memory block

If memory could not be allocated, NULL is returned.

◆ hat_allocator_free()

static void hat_allocator_free ( hat_allocator_t a,
void *  old 
)
inlinestatic

Free memory block.

Parameters
[in]aallocator instance
[in]oldexisting memory block

◆ hat_allocator_realloc()

static void* hat_allocator_realloc ( hat_allocator_t a,
size_t  size,
void *  old 
)
inlinestatic

Reallocate existing memory block.

Parameters
[in]aallocator instance
[in]sizenew memory block size
[in]oldexisting memory block
Returns
new memory block

If memory could not be reallocated, NULL is returned.