-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathobj-pool.h
More file actions
49 lines (38 loc) · 1.69 KB
/
Copy pathobj-pool.h
File metadata and controls
49 lines (38 loc) · 1.69 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* SPDX-License-Identifier: MIT */
/* Copyright (c) 2026 MoatLab, Virginia Tech. */
/*====================================================================*
* pool.h – O(1) object‑pool with optional hugetlb backing
*
* The pool's internal layout is hidden. If you need diagnostic data
* (total number of objects ever allocated) use the accessor
* `get_total_capacity()`.
*====================================================================*/
#ifndef __OBJPOOL_H__
#define __OBJPOOL_H__
#include <stddef.h> /* size_t */
#include <stdbool.h> /* bool */
#ifdef __cplusplus
extern "C" {
#endif
/* ----- opaque handle ------------------------------------------------- */
typedef struct object_pool object_pool;
/* ----- creation / destruction ---------------------------------------- */
object_pool *pool_create(size_t element_size, size_t initial_capacity, size_t chunk_capacity,
bool use_hugepages);
void pool_destroy(object_pool *pool);
/* ----- allocation / de‑allocation ------------------------------------ */
void *pool_alloc(object_pool *pool);
void *pool_alloc_zero(object_pool *pool);
void pool_free(object_pool *pool, void *ptr);
/* ----- diagnostics --------------------------------------------------- */
/* Number of objects that are currently free (debug / statistics). */
size_t pool_available(const object_pool *pool);
/* Total number of objects that have been allocated across all
* chunks ever created for the pool. This is a read‑only value. */
size_t get_total_capacity(const object_pool *pool);
size_t get_total_memory(const object_pool *pool);
size_t get_element_size(const object_pool *pool);
#ifdef __cplusplus
}
#endif
#endif /* __OBJPOOL_H__ */