Zycore 1.5.1.0
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
Allocator.h File Reference
#include <Zycore/Status.h>
#include <Zycore/Types.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.

Classes

struct  ZyanAllocator_
 

Typedefs

typedef ZyanStatus(* ZyanAllocatorAllocate) (struct ZyanAllocator_ *allocator, void **p, ZyanUSize element_size, ZyanUSize n)
 
typedef ZyanStatus(* ZyanAllocatorDeallocate) (struct ZyanAllocator_ *allocator, void *p, ZyanUSize element_size, ZyanUSize n)
 
typedef struct ZyanAllocator_ ZyanAllocator
 

Functions

ZYCORE_EXPORT ZyanStatus ZyanAllocatorInit (ZyanAllocator *allocator, ZyanAllocatorAllocate allocate, ZyanAllocatorAllocate reallocate, ZyanAllocatorDeallocate deallocate)
 
ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanAllocatorZyanAllocatorDefault (void)
 

Typedef Documentation

◆ ZyanAllocator

typedef struct ZyanAllocator_ ZyanAllocator

Defines the ZyanAllocator struct.

This is the base class for all custom allocator implementations.

All fields in this struct should be considered as "private". Any changes may lead to unexpected behavior.

◆ ZyanAllocatorAllocate

typedef ZyanStatus(* ZyanAllocatorAllocate) (struct ZyanAllocator_ *allocator, void **p, ZyanUSize element_size, ZyanUSize n)

Defines the ZyanAllocatorAllocate function prototype.

Parameters
allocatorA pointer to the ZyanAllocator instance.
pReceives a pointer to the first memory block sufficient to hold an array of n elements with a size of element_size.
element_sizeThe size of a single element.
nThe number of elements to allocate storage for.
Returns
A zyan status code.

This prototype is used for the allocate() and reallocate() functions.

The result of the reallocate() function is undefined, if p does not point to a memory block previously obtained by (re-)allocate().

◆ ZyanAllocatorDeallocate

typedef ZyanStatus(* ZyanAllocatorDeallocate) (struct ZyanAllocator_ *allocator, void *p, ZyanUSize element_size, ZyanUSize n)

Defines the ZyanAllocatorDeallocate function prototype.

Parameters
allocatorA pointer to the ZyanAllocator instance.
pThe pointer obtained from (re-)allocate().
element_sizeThe size of a single element.
nThe number of elements earlier passed to (re-)allocate().
Returns
A zyan status code.

Function Documentation

◆ ZyanAllocatorDefault()

ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanAllocator * ZyanAllocatorDefault ( void  )

Returns the default ZyanAllocator instance.

Returns
A pointer to the default ZyanAllocator instance.

The default allocator uses the default memory manager to allocate memory on the heap.

You should in no case modify the returned allocator instance to avoid unexpected behavior.

◆ ZyanAllocatorInit()

ZYCORE_EXPORT ZyanStatus ZyanAllocatorInit ( ZyanAllocator allocator,
ZyanAllocatorAllocate  allocate,
ZyanAllocatorAllocate  reallocate,
ZyanAllocatorDeallocate  deallocate 
)

Initializes the given ZyanAllocator instance.

Parameters
allocatorA pointer to the ZyanAllocator instance.
allocateThe allocate function.
reallocateThe reallocate function.
deallocateThe deallocate function.
Returns
A zyan status code.