mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
lv_mem_free: periodically peform full defrag
This commit is contained in:
parent
9ad1e31521
commit
6563f2fa0d
@ -28,6 +28,10 @@
|
|||||||
#define LV_MEM_ADD_JUNK 1
|
#define LV_MEM_ADD_JUNK 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef LV_MEM_FULL_DEFRAG_CNT
|
||||||
|
#define LV_MEM_FULL_DEFRAG_CNT 16
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef LV_ARCH_64
|
#ifdef LV_ARCH_64
|
||||||
#define MEM_UNIT uint64_t
|
#define MEM_UNIT uint64_t
|
||||||
#else
|
#else
|
||||||
@ -156,6 +160,7 @@ void * lv_mem_alloc(size_t size)
|
|||||||
#endif
|
#endif
|
||||||
void * alloc = NULL;
|
void * alloc = NULL;
|
||||||
|
|
||||||
|
printf("alloc: %d\n", size);
|
||||||
#if LV_MEM_CUSTOM == 0
|
#if LV_MEM_CUSTOM == 0
|
||||||
/*Use the built-in allocators*/
|
/*Use the built-in allocators*/
|
||||||
lv_mem_ent_t * e = NULL;
|
lv_mem_ent_t * e = NULL;
|
||||||
@ -218,20 +223,30 @@ void lv_mem_free(const void * data)
|
|||||||
|
|
||||||
#if LV_MEM_CUSTOM == 0
|
#if LV_MEM_CUSTOM == 0
|
||||||
#if LV_MEM_AUTO_DEFRAG
|
#if LV_MEM_AUTO_DEFRAG
|
||||||
/* Make a simple defrag.
|
static uint16_t full_defrag_cnt = 0;
|
||||||
* Join the following free entries after this*/
|
full_defrag_cnt++;
|
||||||
lv_mem_ent_t * e_next;
|
if(full_defrag_cnt < LV_MEM_FULL_DEFRAG_CNT) {
|
||||||
e_next = ent_get_next(e);
|
/* Make a simple defrag.
|
||||||
while(e_next != NULL) {
|
* Join the following free entries after this*/
|
||||||
if(e_next->header.s.used == 0) {
|
lv_mem_ent_t * e_next;
|
||||||
e->header.s.d_size += e_next->header.s.d_size + sizeof(e->header);
|
e_next = ent_get_next(e);
|
||||||
|
while(e_next != NULL) {
|
||||||
|
if(e_next->header.s.used == 0) {
|
||||||
|
e->header.s.d_size += e_next->header.s.d_size + sizeof(e->header);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
e_next = ent_get_next(e_next);
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
break;
|
full_defrag_cnt = 0;
|
||||||
}
|
lv_mem_defrag();
|
||||||
e_next = ent_get_next(e_next);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif /*LV_MEM_AUTO_DEFRAG*/
|
||||||
#else /*Use custom, user defined free function*/
|
#else /*Use custom, user defined free function*/
|
||||||
#if LV_ENABLE_GC == 0
|
#if LV_ENABLE_GC == 0
|
||||||
LV_MEM_CUSTOM_FREE(e);
|
LV_MEM_CUSTOM_FREE(e);
|
||||||
@ -771,13 +786,12 @@ static lv_mem_ent_t * ent_get_next(lv_mem_ent_t * act_e)
|
|||||||
static void * ent_alloc(lv_mem_ent_t * e, size_t size)
|
static void * ent_alloc(lv_mem_ent_t * e, size_t size)
|
||||||
{
|
{
|
||||||
void * alloc = NULL;
|
void * alloc = NULL;
|
||||||
|
printf("%s, size:%d\n", e->header.s.used == 0 ? "free" : "used", e->header.s.d_size);
|
||||||
/*If the memory is free and big enough then use it */
|
/*If the memory is free and big enough then use it */
|
||||||
if(e->header.s.used == 0 && e->header.s.d_size >= size) {
|
if(e->header.s.used == 0 && e->header.s.d_size >= size) {
|
||||||
/*Truncate the entry to the desired size */
|
/*Truncate the entry to the desired size */
|
||||||
ent_trunc(e, size),
|
ent_trunc(e, size);
|
||||||
|
e->header.s.used = 1;
|
||||||
e->header.s.used = 1;
|
|
||||||
|
|
||||||
/*Save the allocated data*/
|
/*Save the allocated data*/
|
||||||
alloc = &e->first_data;
|
alloc = &e->first_data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user