libdatatypes 0.3.2
Abstract datatypes for C.
Loading...
Searching...
No Matches
pool.h File Reference

Allocate memory blocks of same sizes. More...

#include <stdint.h>
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  Pool
 Allocate groups of equal-sized chunks of memory. More...
 
struct  MemoryPool
 This memory pool allocates blocks of memory and grows automatically. More...
 
struct  MemoryPool::_MemoryBlock
 Blocks of memory are stored in a singly-linked list. More...
 
struct  MemoryPool::_MemoryPtrBlock
 Freed pointers are stored in blocks holding addresses. More...
 

Functions

MemoryPoolmemory_pool_new (size_t item_size, size_t block_size)
 
void memory_pool_destroy (MemoryPool *pool)
 

Detailed Description

Allocate memory blocks of same sizes.

Author
Sebastian Fedrau sebas.nosp@m.tian.nosp@m..fedr.nosp@m.au@g.nosp@m.mail..nosp@m.com

Definition in file pool.h.


Data Structure Documentation

◆ MemoryPool

struct MemoryPool

This memory pool allocates blocks of memory and grows automatically.

Definition at line 44 of file pool.h.

Data Fields
struct _MemoryBlock * block First memory block.
size_t block_size

Number of items a memory memory can hold.

struct _MemoryPtrBlock * free_block First pointer block.
size_t item_size

Size of an allocated item.

Pool padding

Padding.

◆ MemoryPool::_MemoryBlock

struct MemoryPool::_MemoryBlock

Blocks of memory are stored in a singly-linked list.

Definition at line 56 of file pool.h.

Data Fields
int8_t * items

The allocated memory block.

struct _MemoryBlock * next

Pointer to next available memory block or NULL.

size_t offset

Offset of the next available address.

◆ MemoryPool::_MemoryPtrBlock

struct MemoryPool::_MemoryPtrBlock

Freed pointers are stored in blocks holding addresses.

Definition at line 72 of file pool.h.

Data Fields
void ** items

Array containing freed pointers.

struct _MemoryPtrBlock * next

Pointer to next memory or NULL.

size_t offset

Offset to find next available position in items array.

Function Documentation

◆ memory_pool_destroy()

void memory_pool_destroy ( MemoryPool pool)
Parameters
poolMemoryPool to destroy

Destroys the given MemoryPool.

Definition at line 202 of file pool.c.

◆ memory_pool_new()

MemoryPool * memory_pool_new ( size_t  item_size,
size_t  block_size 
)
Parameters
item_sizesize of allocated items
block_sizenumber of elements a memory can hold
Returns
a new pool

Creates a new MemoryPool.

Definition at line 175 of file pool.c.