| 1 |
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
| 2 |
/*
|
| 3 |
* memory_pool
|
| 4 |
* - memory pool
|
| 5 |
*
|
| 6 |
* Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com>
|
| 7 |
*/
|
| 8 |
|
| 9 |
#ifndef _MEMORY_POOL_H_
|
| 10 |
#define _MEMORY_POOL_H_
|
| 11 |
|
| 12 |
#include <stddef.h>
|
| 13 |
|
| 14 |
struct memory_pool_t
|
| 15 |
{
|
| 16 |
size_t node_size;
|
| 17 |
size_t node_count_per_chunk;
|
| 18 |
int chunk_count;
|
| 19 |
int chunk_count_limit;
|
| 20 |
void **p_chunks;
|
| 21 |
void *p_free;
|
| 22 |
int node_count_allocated;
|
| 23 |
int node_count_free;
|
| 24 |
int node_count_total;
|
| 25 |
};
|
| 26 |
typedef struct memory_pool_t MEMORY_POOL;
|
| 27 |
|
| 28 |
extern MEMORY_POOL *memory_pool_init(size_t node_size, size_t node_count_per_chunk, int chunk_count_limit);
|
| 29 |
extern void memory_pool_cleanup(MEMORY_POOL *p_pool);
|
| 30 |
|
| 31 |
extern void *memory_pool_alloc(MEMORY_POOL *p_pool);
|
| 32 |
extern void memory_pool_free(MEMORY_POOL *p_pool, void *p_node);
|
| 33 |
|
| 34 |
// For debug only
|
| 35 |
extern int memory_pool_check_node(MEMORY_POOL *p_pool, void *p_node);
|
| 36 |
|
| 37 |
#endif //_MEMORY_POOL_H_
|