-
Notifications
You must be signed in to change notification settings - Fork 1
/
embedded_alloc.h
60 lines (48 loc) · 1.24 KB
/
embedded_alloc.h
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
50
51
52
53
54
55
56
57
58
59
60
/*
* embedded_alloc.h - version: 1.0
*
* Created by Haroldo Luiz Moretti do Amaral, 18/09/2015
* Released into the public domain
*/
#ifndef EMBEDDED_ALLOC_H_ /* Include guard */
#define EMBEDDED_ALLOC_H_
#include <stdint.h>
/*
* Initializes the buffer used to handle the variables
* Starts the first meta_header
*/
void embedded_alloc_init(void *buff, uint16_t buffer_size);
/*
* Set the size of the current buffer (static variable)
* Allows to use multiple buffers
*/
void set_block_size(uint16_t size);
/*
* Set the upper limit (address) of the current buffer
* Used with multiple buffers
*/
void set_block_limit(void *var, uint16_t size);
/*
* allocate the variable in the buffer (if there is a minimum of bytes needed)
*/
void *embedded_alloc(void *buff, uint16_t num);
/*
* frees an allocated variable
*/
void embedded_free(void *var);
/*
* frees the memory block optimizing the free space
* checks whether the next block is free and joining its size
* In the end you can clear the data - saves 0 - enable_cleaning()
*/
void embedded_smart_free(void *var);
/*
* Enable the cleaning in the smart_free
*/
void enable_cleaning();
/*
* Disable the cleaning in the smart_free
*/
void disable_cleaning();
#endif // EMBEDDED_ALLOC_H_