Yes you can get the free memory however it will not tell you how large the biggest continues block is. If memory is fragmented then you will have trouble getting a large block.Hi all,
Is there a way of getting the free memory at runtime for a program using the C SDK? I'm not currently using dynamic allocation e.g. malloc, so could probably estimate, but it would be good if there was a function that could give me a run time reading.
Cheers.
Phill.
Make sure you have this header included
Code:
#include<malloc.h>ORuint32_t getTotalHeap(void);uint32_t getFreeHeap(void);
Code:
printf ("System Reports Approximately %d bytes free\n\r", getFreeHeap());
Code:
int ptsh_mem (int argc, char** argv){ char* free_memory = NULL; uint8_t x; for (x = 1; x < 250; x++) { free_memory = malloc(1024 * x); if (free_memory == NULL) { break; } free(free_memory); free_memory = NULL; } printf ("System Reports Approximately %d K free\n\r", (x - 1)); return 0;}
target_compile_definitions({PROJECT NAME} PUBLIC -DPICO_MALLOC_PANIC=0)
How are you thinking of using this memory? if you re going to be freeing it back and reallocating it I would not use the SDK memory manager. If you need details just ask.
Statistics: Posted by DarkElvenAngel — Sat Nov 02, 2024 2:10 pm