l10n: bg.po: Updated Bulgarian translation (5652t)
[git.git] / mem-pool.h
blobd1c66413ec322104f6199cc2248466c734cee868
1 #ifndef MEM_POOL_H
2 #define MEM_POOL_H
4 struct mp_block {
5 struct mp_block *next_block;
6 char *next_free;
7 char *end;
8 uintmax_t space[FLEX_ARRAY]; /* more */
9 };
11 struct mem_pool {
12 struct mp_block *mp_block;
15 * The amount of available memory to grow the pool by.
16 * This size does not include the overhead for the mp_block.
18 size_t block_alloc;
20 /* The total amount of memory allocated by the pool. */
21 size_t pool_alloc;
25 * Initialize mem_pool with specified initial size.
27 void mem_pool_init(struct mem_pool *pool, size_t initial_size);
30 * Discard all the memory the memory pool is responsible for.
32 void mem_pool_discard(struct mem_pool *pool, int invalidate_memory);
35 * Alloc memory from the mem_pool.
37 void *mem_pool_alloc(struct mem_pool *pool, size_t len);
40 * Allocate and zero memory from the memory pool.
42 void *mem_pool_calloc(struct mem_pool *pool, size_t count, size_t size);
45 * Allocate memory from the memory pool and copy str into it.
47 char *mem_pool_strdup(struct mem_pool *pool, const char *str);
48 char *mem_pool_strndup(struct mem_pool *pool, const char *str, size_t len);
51 * Allocate memory from the memory pool and format a string into it.
53 char *mem_pool_strfmt(struct mem_pool *pool, const char *fmt, ...);
56 * Move the memory associated with the 'src' pool to the 'dst' pool. The 'src'
57 * pool will be empty and not contain any memory. It still needs to be free'd
58 * with a call to `mem_pool_discard`.
60 void mem_pool_combine(struct mem_pool *dst, struct mem_pool *src);
63 * Check if a memory pointed at by 'mem' is part of the range of
64 * memory managed by the specified mem_pool.
66 int mem_pool_contains(struct mem_pool *pool, void *mem);
68 #endif