utils
utilities in C for microcontrollers
Data Structures | Macros | Functions
pool.h File Reference

A generic memory pool allocator. More...

#include <stddef.h>
#include <stdbool.h>
#include "slist.h"

Go to the source code of this file.

Data Structures

union  pool_NAME_private
 private instance type generated by POOL with name set to NAME, type set to TYPE, and size set to SIZE More...
 
struct  pool_NAME
 instance type generated by POOL with name set to NAME, type set to TYPE, and size set to SIZE More...
 

Macros

#define POOL(name, type, size)
 Generates the pool api. More...
 

Functions

static int pool_NAME_init (struct pool_NAME *self)
 init function generated by POOL with name set to NAME, type set to TYPE, and size set to SIZE More...
 
static TYPE * pool_NAME_alloc (struct pool_NAME *self)
 alloc function generated by POOL with name set to NAME, type set to TYPE, and size set to SIZE More...
 
static void pool_NAME_free (struct pool_NAME *self, TYPE *obj)
 free function generated by POOL with name set to NAME, type set to TYPE, and size set to SIZE More...
 

Detailed Description

A generic memory pool allocator.

Macro Definition Documentation

◆ POOL

#define POOL (   name,
  type,
  size 
)

Generates the pool api.

Parameters
namea name for the api with the given type and size
typethe type of objects to allocate
sizethe maximum number of objects that can be allocated

Function Documentation

◆ pool_NAME_alloc()

TYPE * pool_NAME_alloc ( struct pool_NAME self)
inlinestatic

alloc function generated by POOL with name set to NAME, type set to TYPE, and size set to SIZE

Parameters
selfthe pool_NAME from which to allocate
Returns
pointer to TYPE if successful, NULL if not successful

◆ pool_NAME_free()

void pool_NAME_free ( struct pool_NAME self,
TYPE *  obj 
)
inlinestatic

free function generated by POOL with name set to NAME, type set to TYPE, and size set to SIZE

Parameters
selfthe pool_NAME from which to allocate
objthe object to return to the pool self

◆ pool_NAME_init()

int pool_NAME_init ( struct pool_NAME self)
inlinestatic

init function generated by POOL with name set to NAME, type set to TYPE, and size set to SIZE

Parameters
selfthe pool_NAME to initialize
Returns
0 if successful