24 #include "microui_heap.h"
25 #include "BESTFIT_ALLOCATOR.h"
34 #define BESTFITALLOCATOR_HEADER_SIZE (68)
41 #define BESTFITALLOCATOR_BLOCK_SIZE(block) ((*(uint32_t *)((block) - sizeof(uint32_t))) & 0x7ffffff)
47 static BESTFIT_ALLOCATOR image_heap;
48 static uint32_t heap_size;
49 static uint32_t free_space;
50 static uint32_t allocated_blocks_number;
56 uint32_t MICROUI_HEAP_total_space(
void) {
60 uint32_t MICROUI_HEAP_free_space(
void) {
64 uint32_t MICROUI_HEAP_number_of_allocated_blocks(
void) {
65 return allocated_blocks_number;
72 void LLUI_DISPLAY_IMPL_imageHeapInitialize(uint8_t *heap_start, uint8_t *heap_limit) {
73 heap_size = heap_limit - heap_start - BESTFITALLOCATOR_HEADER_SIZE;
74 free_space = heap_size;
75 BESTFIT_ALLOCATOR_new(&image_heap);
76 BESTFIT_ALLOCATOR_initialize(&image_heap, (int32_t)heap_start, (int32_t)heap_limit);
79 uint8_t * LLUI_DISPLAY_IMPL_imageHeapAllocate(uint32_t size) {
80 uint8_t *addr = (uint8_t *)BESTFIT_ALLOCATOR_allocate(&image_heap, (int32_t)size);
82 if ((uint8_t *)0 != addr) {
83 free_space -= BESTFITALLOCATOR_BLOCK_SIZE(addr);
84 allocated_blocks_number++;
89 void LLUI_DISPLAY_IMPL_imageHeapFree(uint8_t *block) {
90 free_space += BESTFITALLOCATOR_BLOCK_SIZE(block);
91 allocated_blocks_number--;
92 BESTFIT_ALLOCATOR_free(&image_heap, (
void *)block);