Memory Pool
Create a pool of memory blocks
memory_pool.h
Go to the documentation of this file.
1 /*
2  * author: iancain
3  * date: 10/1/2018
4  * description:
5  * Objective: speed operations of malloc/free and adapt idiomatically and separate memory
6  management from other data storage patterns such as linked lists, stacks,
7  double buffering
8  Limitations: Fixed sized memory blocks. Due to the O(1) requirement only fixed sized
9  memory allocation can be performed. Memory fragmentation and
10  collection/collating operations are not desired due to performance demands
11 
12  Support O(1) operation in acquire and release operations
13  Strategy:
14  stack object to manage memory blocks
15  acquire = pop_front (acquire block off the front/top of stack)
16  release = push_back (release block by putting on back/bottom of stack)
17  */
18 
19 
20 #include <stdlib.h>
21 #include <stdbool.h> // NOTE: c99 bool requires #include <stdbool.h>
22 
23 typedef struct memory_pool memory_pool_t;
24 
27 
29 bool memory_pool_release(memory_pool_t *mp, void * data);
30 
31 // convieneince functions
memory_pool_t * memory_pool_init(size_t count, size_t block_size)
memory pool initializer
Definition: memory_pool.c:90
void memory_pool_dump(memory_pool_t *mp)
memory pool dump function
Definition: memory_pool.c:310
size_t block_size
Definition: memory_pool.c:36
size_t count
Definition: memory_pool.c:35
bool memory_pool_destroy(memory_pool_t *mp)
Definition: memory_pool.c:154
size_t memory_pool_available(memory_pool_t *mp)
memory pool availability function
Definition: memory_pool.c:293
void * memory_pool_acquire(memory_pool_t *mp)
memory pool pop function
Definition: memory_pool.c:214
bool memory_pool_release(memory_pool_t *mp, void *data)
memory pool push function
Definition: memory_pool.c:253