I have a question about memory management

in lv_conf.h

#define LV_MEM_CUSTOM      0
#if LV_MEM_CUSTOM == 0
/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
#  define LV_MEM_SIZE    (1024U * 1024U * 100U)

/* Complier prefix for a big array declaration */
#  define LV_MEM_ATTR

/* Set an address for the memory pool instead of allocating it as an array.
 * Can be in external SRAM too. */
#  define LV_MEM_ADR          0

/* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */
#  define LV_MEM_AUTO_DEFRAG  1
#else       /*LV_MEM_CUSTOM*/
#  define LV_MEM_CUSTOM_INCLUDE <stdlib.h>   /*Header for the dynamic memory function*/
#  define LV_MEM_CUSTOM_ALLOC   malloc       /*Wrapper to malloc*/
#  define LV_MEM_CUSTOM_FREE    free         /*Wrapper to free*/
#endif     /*LV_MEM_CUSTOM*/

and in lv_mem.h

#ifndef LV_MEM_BUF_MAX_NUM
#define LV_MEM_BUF_MAX_NUM    16
#endif

/**********************
 *      TYPEDEFS
 **********************/

/**
 * Heap information structure.
 */
typedef struct {
    uint32_t total_size; /**< Total heap size */
    uint32_t free_cnt;
    uint32_t free_size; /**< Size of available memory */
    uint32_t free_biggest_size;
    uint32_t used_cnt;
    uint32_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;

typedef struct {
    void * p;
    uint16_t size;
    uint8_t used    : 1;
} lv_mem_buf_t;

typedef lv_mem_buf_t lv_mem_buf_arr_t[LV_MEM_BUF_MAX_NUM];
extern lv_mem_buf_arr_t _lv_mem_buf;

may i ask

What is the relationship between LV_MEM_SIZE and LV_MEM_BUF_MAX_NUM ?

What is the significance of the above statement?

typedef lv_mem_buf_t lv_mem_buf_arr_t[LV_MEM_BUF_MAX_NUM];
extern lv_mem_buf_arr_t _lv_mem_buf;

my error is “Error: No free buffer. Increase LV_MEM_BUF_MAX_NUM. (0x00000000) (lv_debug.c #127 lv_debug_log_error())”

littlevgl version is V7.81

1 Like

As far as I know users should never need to change LV_MEM_BUF_MAX_NUM.

However, there was a leak in one of the 7.x versions around 7.8 which resulted in all of these buffers being used very quickly. Please update to release/v7 and see if the issue goes away.

2 Likes

Your advice is useful, thank you very much.