1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_misc/lv_mem.h

142 lines
2.9 KiB
C
Raw Normal View History

2017-11-23 20:42:14 +01:00
/**
2017-11-23 21:28:36 +01:00
* @file lv_mem.h
2017-11-23 20:42:14 +01:00
*
*/
2017-11-23 21:28:36 +01:00
#ifndef LV_MEM_H
#define LV_MEM_H
2017-11-23 20:42:14 +01:00
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
2017-11-23 20:42:14 +01:00
#include <stdint.h>
#include <stddef.h>
2018-07-25 17:57:08 +02:00
#include "lv_log.h"
#include "lv_types.h"
2017-11-23 20:42:14 +01:00
/*********************
* DEFINES
*********************/
#ifndef LV_MEM_BUF_MAX_NUM
#define LV_MEM_BUF_MAX_NUM 16
#endif
2017-11-23 20:42:14 +01:00
/**********************
* TYPEDEFS
**********************/
2019-06-27 18:07:26 -04:00
/**
* Heap information structure.
*/
2017-11-23 20:42:14 +01:00
typedef struct
{
2019-06-27 18:07:26 -04:00
uint32_t total_size; /**< Total heap size */
2017-11-26 11:38:28 +01:00
uint32_t free_cnt;
2019-06-27 18:07:26 -04:00
uint32_t free_size; /**< Size of available memory */
2017-11-26 11:38:28 +01:00
uint32_t free_biggest_size;
2017-12-20 00:47:37 +01:00
uint32_t used_cnt;
2019-06-27 18:07:26 -04:00
uint8_t used_pct; /**< Percentage used */
uint8_t frag_pct; /**< Amount of fragmentation */
2018-06-19 09:49:58 +02:00
} lv_mem_monitor_t;
2017-11-23 20:42:14 +01:00
typedef struct {
void * p;
uint16_t size;
uint8_t used :1;
}lv_mem_buf_t;
2019-12-26 22:12:18 +02:00
typedef lv_mem_buf_t lv_mem_buf_arr_t[LV_MEM_BUF_MAX_NUM];
extern lv_mem_buf_arr_t _lv_mem_buf;
2017-11-23 20:42:14 +01:00
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initiaize the dyn_mem module (work memory and other variables)
*/
2017-11-23 21:28:36 +01:00
void lv_mem_init(void);
2017-11-23 20:42:14 +01:00
2019-12-22 01:35:00 +02:00
/**
* Clean up the memory buffer which frees all the allocated memories.
* @note It work only if `LV_MEM_CUSTOM == 0`
*/
void lv_mem_deinit(void);
2017-11-23 20:42:14 +01:00
/**
* Allocate a memory dynamically
* @param size size of the memory to allocate in bytes
* @return pointer to the allocated memory
*/
2019-12-02 12:20:01 +01:00
void * lv_mem_alloc(size_t size);
2017-11-23 20:42:14 +01:00
/**
* Free an allocated data
* @param data pointer to an allocated memory
*/
2017-11-23 21:28:36 +01:00
void lv_mem_free(const void * data);
2017-11-23 20:42:14 +01:00
/**
* Reallocate a memory with a new size. The old content will be kept.
* @param data 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
*/
2019-12-02 12:20:01 +01:00
void * lv_mem_realloc(void * data_p, size_t new_size);
2017-11-23 20:42:14 +01:00
/**
* Join the adjacent free memory blocks
*/
2017-11-23 21:28:36 +01:00
void lv_mem_defrag(void);
2017-11-23 20:42:14 +01:00
lv_res_t lv_mem_test(void);
2017-11-23 20:42:14 +01:00
/**
* Give information about the work memory of dynamic allocation
* @param mon_p pointer to a dm_mon_p variable,
* the result of the analysis will be stored here
*/
2017-11-26 11:38:28 +01:00
void lv_mem_monitor(lv_mem_monitor_t * mon_p);
2017-11-23 20:42:14 +01:00
/**
* Give the size of an allocated memory
* @param data pointer to an allocated memory
* @return the size of data memory in bytes
*/
uint32_t lv_mem_get_size(const void * data);
2017-11-26 11:38:28 +01:00
/**
* Get a temporal buffer with the given size.
* @param size the required size
*/
void * lv_mem_buf_get(uint32_t size);
/**
* Release a memory buffer
* @param p buffer to release
*/
void lv_mem_buf_release(void * p);
/**
* Free all memory buffers
*/
void lv_mem_buf_free_all(void);
2017-11-23 20:42:14 +01:00
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
2017-11-23 21:28:36 +01:00
#endif /*LV_MEM_H*/