---
name: "Allocator.h"
section: "3"
platform: "linux"
package: "libzycore-doc"
version: "1.5.2-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Allocator.h"
---

# Allocator.h(3)

## NAME

include/Zycore/Allocator.h

## SYNOPSIS

`#include <Zycore/Status.h>`\
 `#include <Zycore/Types.h>`\

### 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** **ZyanAllocator** \* **ZyanAllocatorDefault** (void)\

## Typedef Documentation

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

### typedef ZyanStatus(\* ZyanAllocatorAllocate) (struct ZyanAllocator\_ \*allocator, void \*\*p, ZyanUSize element\_size, ZyanUSize n)

Defines the `ZyanAllocatorAllocate` function prototype.

**Parameters**

*allocator* A pointer to the `ZyanAllocator` instance. \
 *p* Receives a pointer to the first memory block sufficient to hold an array of `n` elements with a size of `element_size`. \
 *element\_size* The size of a single element. \
 *n* The 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()`.

### typedef ZyanStatus(\* ZyanAllocatorDeallocate) (struct ZyanAllocator\_ \*allocator, void \*p, ZyanUSize element\_size, ZyanUSize n)

Defines the `ZyanAllocatorDeallocate` function prototype.

**Parameters**

*allocator* A pointer to the `ZyanAllocator` instance. \
 *p* The pointer obtained from `(re-)allocate()`. \
 *element\_size* The size of a single element. \
 *n* The number of elements earlier passed to `(re-)allocate()`.

**Returns**

A zyan status code.

## Function Documentation

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

### ZYCORE\_EXPORT ZyanStatus ZyanAllocatorInit (ZyanAllocator \* allocator, ZyanAllocatorAllocate allocate, ZyanAllocatorAllocate reallocate, ZyanAllocatorDeallocate deallocate)

Initializes the given `ZyanAllocator` instance.

**Parameters**

*allocator* A pointer to the `ZyanAllocator` instance. \
 *allocate* The allocate function. \
 *reallocate* The reallocate function. \
 *deallocate* The deallocate function.

**Returns**

A zyan status code.

## Author

Generated automatically by Doxygen for Zycore from the source code.
