blob: 210c18988ac77e54dc46fa220a99334d6d0029ea (
plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/**
* @file lv_mem.h
*
*/
#ifndef LV_MEM_H
#define LV_MEM_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include "lv_string.h"
#include "../misc/lv_types.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef void * lv_mem_pool_t;
/**
* Heap information structure.
*/
typedef struct {
size_t total_size; /**< Total heap size */
size_t free_cnt;
size_t free_size; /**< Size of available memory */
size_t free_biggest_size;
size_t used_cnt;
size_t max_used; /**< Max size of Heap memory used */
uint8_t used_pct; /**< Percentage used */
uint8_t frag_pct; /**< Amount of fragmentation */
} lv_mem_monitor_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize to use malloc/free/realloc etc
*/
void lv_mem_init(void);
/**
* Drop all dynamically allocated memory and reset the memory pools' state
*/
void lv_mem_deinit(void);
lv_mem_pool_t lv_mem_add_pool(void * mem, size_t bytes);
void lv_mem_remove_pool(lv_mem_pool_t pool);
/**
* Allocate memory dynamically
* @param size requested size in bytes
* @return pointer to allocated uninitialized memory, or NULL on failure
*/
void * lv_malloc(size_t size);
/**
* Allocate zeroed memory dynamically
* @param size requested size in bytes
* @return pointer to allocated zeroed memory, or NULL on failure
*/
void * lv_malloc_zeroed(size_t size);
/**
* Free an allocated data
* @param data pointer to an allocated memory
*/
void lv_free(void * data);
/**
* Reallocate a memory with a new size. The old content will be kept.
* @param data_p pointer to an allocated memory.
* Its content will be copied to the new memory block and freed
* @param new_size the desired new size in byte
* @return pointer to the new memory, NULL on failure
*/
void * lv_realloc(void * data_p, size_t new_size);
/**
* Used internally to execute a plain `malloc` operation
* @param size size in bytes to `malloc`
*/
void * lv_malloc_core(size_t size);
/**
* Used internally to execute a plain `free` operation
* @param p memory address to free
*/
void lv_free_core(void * p);
/**
* Used internally to execute a plain realloc operation
* @param p memory address to realloc
* @param new_size size in bytes to realloc
*/
void * lv_realloc_core(void * p, size_t new_size);
/**
* Used internally by lv_mem_monitor() to gather LVGL heap state information.
* @param mon_p pointer to lv_mem_monitor_t object to be populated.
*/
void lv_mem_monitor_core(lv_mem_monitor_t * mon_p);
lv_result_t lv_mem_test_core(void);
/**
* @brief Tests the memory allocation system by allocating and freeing a block of memory.
* @return LV_RESULT_OK if the memory allocation system is working properly, or LV_RESULT_INVALID if there is an error.
*/
lv_result_t lv_mem_test(void);
/**
* Give information about the work memory of dynamic allocation
* @param mon_p pointer to a lv_mem_monitor_t variable,
* the result of the analysis will be stored here
*/
void lv_mem_monitor(lv_mem_monitor_t * mon_p);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_MEM_H*/
|