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 
62 void *memarray_alloc(memarray_t *mem);
63 
73 void memarray_free(memarray_t *mem, void *ptr);
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #endif /* MEMARRAY_H */
80 
size_t size
size of single list element
Definition: memarray.h:33
size_t num
max number of elements in list
Definition: memarray.h:34
Memory pool.
Definition: memarray.h:31
void * free_data
memory pool data / head of the free list
Definition: memarray.h:32
stdlib.h wrapper for MSP430
void * memarray_alloc(memarray_t *mem)
Allocate memory chunk in memarray pool.
void memarray_init(memarray_t *mem, void *data, size_t size, size_t num)
Initialize memarray pool with free list.
void memarray_free(memarray_t *mem, void *ptr)
Free memory chunk in memarray pool.