1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/lv_misc/lv_mem.h

128 lines
2.4 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
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
#include "../../lv_conf.h"
#endif
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"
2017-11-23 20:42:14 +01:00
/*********************
* DEFINES
*********************/
2018-09-27 15:03:20 +02:00
// Check windows
#if __WIN64
# define LV_MEM_ENV64
#endif
// Check GCC
#if __GNUC__
# if __x86_64__ || __ppc64__
# define LV_MEM_ENV64
# endif
#endif
2017-11-23 20:42:14 +01:00
/**********************
* TYPEDEFS
**********************/
typedef struct
{
2017-12-20 00:47:37 +01:00
uint32_t total_size;
2017-11-26 11:38:28 +01:00
uint32_t free_cnt;
uint32_t free_size;
uint32_t free_biggest_size;
2017-12-20 00:47:37 +01:00
uint32_t used_cnt;
2017-11-26 11:38:28 +01:00
uint8_t used_pct;
2017-12-20 00:47:37 +01:00
uint8_t frag_pct;
2018-06-19 09:49:58 +02:00
} lv_mem_monitor_t;
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
/**
* Allocate a memory dynamically
* @param size size of the memory to allocate in bytes
* @return pointer to the allocated memory
*/
2017-11-23 21:28:36 +01:00
void * lv_mem_alloc(uint32_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
*/
2017-11-23 21:28:36 +01:00
void * lv_mem_realloc(void * data_p, uint32_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
/**
* 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
2017-11-23 20:42:14 +01:00
/**********************
* MACROS
**********************/
2018-07-25 17:57:08 +02:00
/**
* Halt on NULL pointer
* p pointer to a memory
*/
#if USE_LV_LOG == 0
# define lv_mem_assert(p) {if(p == NULL) while(1); }
#else
2018-07-25 20:39:24 +02:00
# define lv_mem_assert(p) {if(p == NULL) {LV_LOG_ERROR("Out of memory!"); while(1); }}
2018-07-25 17:57:08 +02:00
#endif
2017-11-23 20:42:14 +01:00
#ifdef __cplusplus
} /* extern "C" */
#endif
2017-11-23 21:28:36 +01:00
#endif /*LV_MEM_H*/
2017-11-23 20:42:14 +01:00