-
Notifications
You must be signed in to change notification settings - Fork 0
/
mempool.h
34 lines (26 loc) · 872 Bytes
/
mempool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <string.h>
// Do not perform more allocations than specified.
// Useful to prevent allocation loops
#define MAX_ALLOCATIONS 10240
typedef struct {
// Starting pointer of the array of allocated blocks
void* allocated_blocks[MAX_ALLOCATIONS];
// Cached block that's available immediately to omit scanning the pool
// Useful for a cycle of small frequent allocations/frees
void* cached_block;
// Number of blocks currently allocated
size_t count;
} mempool_t;
typedef enum {
MODE_ALLOCATION = 1 << 0,
MODE_REMOVAL = 1 << 1,
MODE_GLOBAL_CLEANUP_ON_SHUTDOWN = 1 << 2
} track_block_modes_t;
// External functions
int track_block_sort(const void*, const void*);
void print_table_content(void**, size_t);
bool track_block(void*, size_t);
void* safe_alloc(size_t);
void safe_free(void**);
// Definition
#include "mempool.c"