| 1 |
sysadm |
1.1 |
/***************************************************************************
|
| 2 |
|
|
memory_pool.h - description
|
| 3 |
|
|
-------------------
|
| 4 |
|
|
copyright : (C) 2004-2025 by Leaflet
|
| 5 |
|
|
email : leaflet@leafok.com
|
| 6 |
|
|
***************************************************************************/
|
| 7 |
|
|
|
| 8 |
|
|
/***************************************************************************
|
| 9 |
|
|
* *
|
| 10 |
|
|
* This program is free software; you can redistribute it and/or modify *
|
| 11 |
|
|
* it under the terms of the GNU General Public License as published by *
|
| 12 |
|
|
* the Free Software Foundation; either version 3 of the License, or *
|
| 13 |
|
|
* (at your option) any later version. *
|
| 14 |
|
|
* *
|
| 15 |
|
|
***************************************************************************/
|
| 16 |
|
|
|
| 17 |
|
|
#ifndef _MEMORY_POOL_H_
|
| 18 |
|
|
#define _MEMORY_POOL_H_
|
| 19 |
|
|
|
| 20 |
|
|
#include <stddef.h>
|
| 21 |
|
|
|
| 22 |
|
|
struct memory_pool_t
|
| 23 |
|
|
{
|
| 24 |
|
|
size_t node_size;
|
| 25 |
|
|
size_t node_count_per_chunk;
|
| 26 |
|
|
int chunk_count;
|
| 27 |
|
|
int chunk_count_limit;
|
| 28 |
|
|
void **p_chunks;
|
| 29 |
|
|
void *p_free;
|
| 30 |
|
|
int node_count_allocated;
|
| 31 |
|
|
int node_count_free;
|
| 32 |
|
|
int node_count_total;
|
| 33 |
|
|
};
|
| 34 |
|
|
typedef struct memory_pool_t MEMORY_POOL;
|
| 35 |
|
|
|
| 36 |
|
|
extern MEMORY_POOL *memory_pool_init(size_t node_size, size_t node_count_per_chunk, int chunk_count_limit);
|
| 37 |
|
|
extern void memory_pool_cleanup(MEMORY_POOL *p_pool);
|
| 38 |
|
|
|
| 39 |
|
|
extern void *memory_pool_alloc(MEMORY_POOL *p_pool);
|
| 40 |
|
|
extern void memory_pool_free(MEMORY_POOL *p_pool, void *p_node);
|
| 41 |
|
|
|
| 42 |
|
|
// For debug only
|
| 43 |
|
|
extern int memory_pool_check_node(MEMORY_POOL *p_pool, void *p_node);
|
| 44 |
|
|
|
| 45 |
|
|
#endif //_MEMORY_POOL_H_
|