data-structures-c
Loading...
Searching...
No Matches
pool.h File Reference

Pool allocator. More...

#include "align.h"
#include <stdalign.h>
#include <stddef.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  pool_free_node
 Pool node struct. More...
 
struct  pool
 Pool struct. More...
 

Functions

static void pool_deallocate_all (struct pool *self)
 Deallocate pool and restore all free nodes.
 
static void pool_init (struct pool *self, const size_t len, unsigned char *backing_buf, const size_t data_size, const size_t data_alignment)
 Initialize pool for given data size and alignment.
 
static void * pool_allocate (struct pool *self)
 Get a pointer to a free block of previously given data size.
 
static void pool_deallocate (struct pool *self, void *ptr)
 Free a memory chunk for further reuse.
 

Detailed Description

Function Documentation

◆ pool_allocate()

static void * pool_allocate ( struct pool * self)
inlinestatic

Get a pointer to a free block of previously given data size.

Parameters
[in]selfPool pointer
Returns
A pointer to a zeroed-out memory chunk of data size.

◆ pool_deallocate()

static void pool_deallocate ( struct pool * self,
void * ptr )
inlinestatic

Free a memory chunk for further reuse.

Parameters
[in]selfPool pointer
[in]ptrPointer to memory chunk

◆ pool_deallocate_all()

static void pool_deallocate_all ( struct pool * self)
inlinestatic

Deallocate pool and restore all free nodes.

Parameters
[in]selfThe pool pointer.

◆ pool_init()

static void pool_init ( struct pool * self,
const size_t len,
unsigned char * backing_buf,
const size_t data_size,
const size_t data_alignment )
inlinestatic

Initialize pool for given data size and alignment.

Parameters
[in]selfpool pointer
[in]lenbacking buffer length
[in]backing_bufbacking buffer
[in]data_sizedata size
[in]data_alignmentdata alignment