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;
73 void LLUI_DISPLAY_IMPL_imageHeapInitialize(uint8_t* heap_start, uint8_t* heap_limit) {
74 heap_size = heap_limit - heap_start - BESTFITALLOCATOR_HEADER_SIZE;
75 free_space = heap_size;
76 BESTFIT_ALLOCATOR_new(&image_heap);
77 BESTFIT_ALLOCATOR_initialize(&image_heap, (int32_t)heap_start, (int32_t)heap_limit);
80 uint8_t* LLUI_DISPLAY_IMPL_imageHeapAllocate(uint32_t size) {
81 uint8_t* addr = (uint8_t*)BESTFIT_ALLOCATOR_allocate(&image_heap, (int32_t)size);
83 if ((uint8_t*)0 != addr) {
84 free_space -= BESTFITALLOCATOR_BLOCK_SIZE(addr);
85 allocated_blocks_number++;
90 void LLUI_DISPLAY_IMPL_imageHeapFree(uint8_t* block) {
91 free_space += BESTFITALLOCATOR_BLOCK_SIZE(block);
92 allocated_blocks_number--;
93 BESTFIT_ALLOCATOR_free(&image_heap, (
void*)block);