Forum Discussion
Altera_Forum
Honored Contributor
19 years agoMemory statistics
Hi all, is it somehow possible to obtain statistic information about the memory usage of a NIOS2 program at runtime? I tried to use the "struct mstats" from the GNU extensions but it seems th...
Altera_Forum
Honored Contributor
19 years agoHi,
i found a WORK AROUND to optain the approximated memory allocation. This solution uses the function sbrk to optain the current top of the heap pointer and assumes, that the heap is allways placed at last in the memory device. So for non uCOS applications, it ignores the stack allocation.#include "system.h"# include <unistd.h>
# define CONCAT(A,B) A# # B# define CONCAT_MACRO(X,Y) CONCAT(X,Y) // does first Macro expandation and then concatenation# define MEM_START CONCAT_MACRO(ALT_RWDATA_DEVICE,_BASE)# define MEM_END (CONCAT_MACRO(ALT_RWDATA_DEVICE,_BASE) + CONCAT_MACRO(ALT_RWDATA_DEVICE,_SPAN))
...
printf("used memory: %d\n",(unsigned int) sbrk(0) - MEM_START);
printf("free memory: %d\n",MEM_END - (unsigned int) sbrk(0)); If you need it the amount of bytes more detailed, you can use information from mallinfo and stack allocation in non-ucos applications. Regards