Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_misc/lv_mem.h
1476 views
1
/**
2
* @file lv_mem.h
3
*
4
*/
5
6
#ifndef LV_MEM_H
7
#define LV_MEM_H
8
9
#ifdef __cplusplus
10
extern "C" {
11
#endif
12
13
14
/*********************
15
* INCLUDES
16
*********************/
17
#ifdef LV_CONF_INCLUDE_SIMPLE
18
#include "lv_conf.h"
19
#else
20
#include "../../lv_conf.h"
21
#endif
22
23
#include <stdint.h>
24
#include <stddef.h>
25
#include "lv_log.h"
26
27
/*********************
28
* DEFINES
29
*********************/
30
// Check windows
31
#ifdef __WIN64
32
//# define LV_MEM_ENV64
33
#endif
34
35
// Check GCC
36
#ifdef __GNUC__
37
# if defined(__x86_64__) || defined(__ppc64__)
38
//# define LV_MEM_ENV64
39
# endif
40
#endif
41
42
/**********************
43
* TYPEDEFS
44
**********************/
45
46
typedef struct
47
{
48
uint32_t total_size;
49
uint32_t free_cnt;
50
uint32_t free_size;
51
uint32_t free_biggest_size;
52
uint32_t used_cnt;
53
uint8_t used_pct;
54
uint8_t frag_pct;
55
} lv_mem_monitor_t;
56
57
/**********************
58
* GLOBAL PROTOTYPES
59
**********************/
60
61
62
/**
63
* Initiaize the dyn_mem module (work memory and other variables)
64
*/
65
void lv_mem_init(void);
66
67
/**
68
* Allocate a memory dynamically
69
* @param size size of the memory to allocate in bytes
70
* @return pointer to the allocated memory
71
*/
72
void * lv_mem_alloc(uint32_t size);
73
74
/**
75
* Free an allocated data
76
* @param data pointer to an allocated memory
77
*/
78
void lv_mem_free(const void * data);
79
80
/**
81
* Reallocate a memory with a new size. The old content will be kept.
82
* @param data pointer to an allocated memory.
83
* Its content will be copied to the new memory block and freed
84
* @param new_size the desired new size in byte
85
* @return pointer to the new memory
86
*/
87
void * lv_mem_realloc(void * data_p, uint32_t new_size);
88
89
/**
90
* Join the adjacent free memory blocks
91
*/
92
void lv_mem_defrag(void);
93
94
/**
95
* Give information about the work memory of dynamic allocation
96
* @param mon_p pointer to a dm_mon_p variable,
97
* the result of the analysis will be stored here
98
*/
99
void lv_mem_monitor(lv_mem_monitor_t * mon_p);
100
101
/**
102
* Give the size of an allocated memory
103
* @param data pointer to an allocated memory
104
* @return the size of data memory in bytes
105
*/
106
uint32_t lv_mem_get_size(const void * data);
107
108
109
/**********************
110
* MACROS
111
**********************/
112
113
/**
114
* Halt on NULL pointer
115
* p pointer to a memory
116
*/
117
#if USE_LV_LOG == 0
118
# define lv_mem_assert(p) {if(p == NULL) while(1); }
119
#else
120
# define lv_mem_assert(p) {if(p == NULL) {LV_LOG_ERROR("Out of memory!"); while(1); }}
121
#endif
122
#ifdef __cplusplus
123
} /* extern "C" */
124
#endif
125
126
#endif /*LV_MEM_H*/
127
128
129