libclod
C library for interacting with NBTs, region files, LOD data and other things.
Loading...
Searching...
No Matches
memory.h File Reference

Memory allocation methods. More...

#include <clod/lib.h>

Go to the source code of this file.

Classes

struct  clod_allocator
 Allocator. More...
struct  clod_allocator_opts
 Configuration options for libclod's memory allocator. More...

Functions

clod_allocatorclod_allocator_create (const struct clod_allocator_opts *opts)
void clod_allocator_destroy (clod_allocator *allocator)

Detailed Description

Memory allocation methods.

Definition in file memory.h.

Function Documentation

◆ clod_allocator_create()

clod_allocator * clod_allocator_create ( const struct clod_allocator_opts * opts)

Create a memory allocator.

It is not thread safe. Instead, make a dedicated allocator for each thread, and if you need to free memory in a different thread from where it was allocated - fix your program architecture.

Allocations are aligned to either the power of two equal to or greater than size or the configured page size; whichever is smaller.

The contents of allocated memory is undefined.

Allocating a size of zero returns a non-null non-unique pointer that can be freed. Freeing nullptr does nothing.

Parameters
[in]opts(nullable) Allocator configuration options.
Returns
New allocator, or nullptr on allocation failure or invalid options.

Definition at line 6 of file memory.c.

◆ clod_allocator_destroy()

void clod_allocator_destroy ( clod_allocator * allocator)

Free a whole memory allocator that was created with clod_allocator_create. All memory allocated with the allocator is also freed.

Parameters
[in]allocatorMemory allocator to free.

Definition at line 30 of file memory.c.