memarray.h
1 /*
2  * Copyright (C) 2018 Tobias Heider <heidert@nm.ifi.lmu.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
18 #ifndef MEMARRAY_H
19 #define MEMARRAY_H
20 
21 #include <stdint.h>
22 #include <stdlib.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
31 typedef struct {
32  void *free_data;
33  size_t size;
34  size_t num;
35 } memarray_t;
36 
50 void memarray_init(memarray_t *mem, void *data, size_t size, size_t num);
51 
64 void *memarray_alloc(memarray_t *mem);
65 
76 void *memarray_calloc(memarray_t *mem);
77 
87 void memarray_free(memarray_t *mem, void *ptr);
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif /* MEMARRAY_H */
94 
memarray_t::free_data
void * free_data
memory pool data / head of the free list
Definition: memarray.h:32
memarray_free
void memarray_free(memarray_t *mem, void *ptr)
Free memory chunk in memarray pool.
memarray_t::size
size_t size
size of single list element
Definition: memarray.h:33
memarray_t
Memory pool.
Definition: memarray.h:31
memarray_alloc
void * memarray_alloc(memarray_t *mem)
Allocate memory chunk in memarray pool.
memarray_calloc
void * memarray_calloc(memarray_t *mem)
Allocate and clear memory chunk in memarray pool.
memarray_init
void memarray_init(memarray_t *mem, void *data, size_t size, size_t num)
Initialize memarray pool with free list.
memarray_t::num
size_t num
max number of elements in list
Definition: memarray.h:34