2018-02-11 09:26 PM
Hi,
I tried doing malloc(x) and free(x) recursively till it returns null. x is always incrementing. Global interrupts are disabled before malloc and enable after free. There is no code in between malloc and free.
But every time I tried malloc and free sometimes I get the same address but sometimes different. Am trying this on STMF767ZI (M7).
Logs
Aim: Determine the heap size at runtime.
Let me know if you have any simple way to determine heap size at runtime.
#free-the-mallocs2018-02-12 05:50 AM
I don't know your environment, but for GCC, the linker can calculate the size for reference at runtime. For example, in the linker script:
heap_size = ORIGIN(RAM) + LENGTH(RAM) - __bss_end__;
ASSERT(heap_size >= 128K, 'Available heap < 128K');
The ASSERT is nice because it results in a link-time error if the available heap size is below the desired threshold.
Then in C code declare with:
extern char heap_size[];
and use as:
(size_t)heap_size