mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 10:18:35 -07:00
TLSF memory allocator. Less free flash, moar free ram. (#3572)
* add tlsf as submodule * libs: tlsf * Furi: tlsf as allocator * Furi: heap walker * shmal fixshesh * f18: tlsf * PVS: ignore tlsf * I like to moving * merge upcoming changes * memmgr: alloc aligned, realloc * Furi: distinct name for auxiliary memory pool * Furi: put idle and timer thread to mem2 * Furi: fix smal things in allocator * Furi: remove aligned_free. Use free instead. * aligned_malloc -> aligned_alloc * aligned_alloc, parameters order * aligned_alloc: check that alignment is correct * unit test: malloc * unit tests: realloc and test with memory fragmentation * unit tests: aligned_alloc * update api * updater: properly read large update file Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include <furi_hal_memory.h>
|
||||
|
||||
extern void* pvPortMalloc(size_t xSize);
|
||||
extern void* pvPortAllocAligned(size_t xSize, size_t xAlignment);
|
||||
extern void* pvPortRealloc(void* pv, size_t xSize);
|
||||
extern void vPortFree(void* pv);
|
||||
extern size_t xPortGetFreeHeapSize(void);
|
||||
extern size_t xPortGetTotalHeapSize(void);
|
||||
@@ -18,18 +20,7 @@ void free(void* ptr) {
|
||||
}
|
||||
|
||||
void* realloc(void* ptr, size_t size) {
|
||||
if(size == 0) {
|
||||
vPortFree(ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* p = pvPortMalloc(size);
|
||||
if(ptr != NULL) {
|
||||
memcpy(p, ptr, size);
|
||||
vPortFree(ptr);
|
||||
}
|
||||
|
||||
return p;
|
||||
return pvPortRealloc(ptr, size);
|
||||
}
|
||||
|
||||
void* calloc(size_t count, size_t size) {
|
||||
@@ -47,6 +38,10 @@ char* strdup(const char* s) {
|
||||
return y;
|
||||
}
|
||||
|
||||
void* aligned_alloc(size_t alignment, size_t size) {
|
||||
return pvPortAllocAligned(size, alignment);
|
||||
}
|
||||
|
||||
size_t memmgr_get_free_heap(void) {
|
||||
return xPortGetFreeHeapSize();
|
||||
}
|
||||
@@ -79,33 +74,17 @@ void* __wrap__realloc_r(struct _reent* r, void* ptr, size_t size) {
|
||||
return realloc(ptr, size);
|
||||
}
|
||||
|
||||
void* memmgr_alloc_from_pool(size_t size) {
|
||||
void* memmgr_aux_pool_alloc(size_t size) {
|
||||
void* p = furi_hal_memory_alloc(size);
|
||||
if(p == NULL) p = malloc(size);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
size_t memmgr_pool_get_free(void) {
|
||||
size_t memmgr_aux_pool_get_free(void) {
|
||||
return furi_hal_memory_get_free();
|
||||
}
|
||||
|
||||
size_t memmgr_pool_get_max_block(void) {
|
||||
return furi_hal_memory_max_pool_block();
|
||||
}
|
||||
|
||||
void* aligned_malloc(size_t size, size_t alignment) {
|
||||
void* p1; // original block
|
||||
void** p2; // aligned block
|
||||
int offset = alignment - 1 + sizeof(void*);
|
||||
if((p1 = (void*)malloc(size + offset)) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
p2 = (void**)(((size_t)(p1) + offset) & ~(alignment - 1));
|
||||
p2[-1] = p1;
|
||||
return p2;
|
||||
}
|
||||
|
||||
void aligned_free(void* p) {
|
||||
free(((void**)p)[-1]);
|
||||
}
|
||||
Reference in New Issue
Block a user