interplane.Get Omega
Read in your language

klib

[Ported from github.com/attractivechaos/klib] added block arena

Brought by drakestapleton

branch master Branches Tags History

klib / kbarena.h

46 lines · 921 bytes Raw Blame History
1#ifndef AC_KBARENA_H
2#define AC_KBARENA_H
3
4#include <stddef.h>
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10/**
11 * Initialize a blocked arena
12 *
13 * @param blen block length in bytes
14 *
15 * @return pointer to a blocked arena
16 */
17void *kba_init(unsigned blen);
18
19/** Destroy a blocked arena */
20void kba_destroy(void *kba);
21
22/**
23 * Allocate memory from a blocked arena
24 *
25 * @param len size of the memory to allocate
26 * @param aln alignment; must be power of 2
27 *
28 * @return pointer to the memory on success; NULL on insufficient memory or
29 * when len is longer than block length
30 */
31void *kba_alloc(void *kba, unsigned len, unsigned aln);
32
33/** Save the state */
34int kba_save(void *kba);
35
36/** Restore the state (effectively free all memory allocated after the pairing save) */
37int kba_restore(void *kba);
38
39/** Get the capacity in byte */
40size_t kba_capacity(const void *ba_);
41
42#ifdef __cplusplus
43}
44#endif
45
46#endif