Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12690 Discussions

How to analyze memory requirements of a program?

Altera_Forum
Honored Contributor II
1,130 Views

Does any one knows how to get real requirements for stack and heap memory? 

And not that message from IDE for each project "16Mb free for stack and heap"? 

Any info please. 

Target system NiosII CPU standart design.
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
416 Views

Hmm. I'm looking at this problem myself right now... 

 

Several things: 

a: Use 'objdump -h' (nios2-elf-objdump) from the nios shell on the .elf file. 

This should give you some info on the "static" sizes of things like code, data, bss. 

 

b: for ucos task stacks, note that sizeof(OS_STK) is 4, not 1. So your stack usage may be 4 x higher than you think.  

 

c: If you use LWIP, then 8KB per possible task of stack is preallocated in sys_arch.c. On my system, that took up 504K. A sane person might wish to alter this to use a less brain-dead approach. Also, if a task started with sys_new_task terminates, the stack (and the task priority) are not 'reclaimed' in any way. 

 

d: the newlib 'mallinfo' calls are effectively pointless. Calling 'mallinfo' will give you an idea of how much heap you're using, but you have - AFAIK - NO WAY of telling how much is left, because malloc itself requests memory via sbrk(), which seems to have no concept of the amount of available memory. It just keeps giving malloc more and more... 

 

Has anybody attempted to rebuild newlib yet? 

 

- Roddy
0 Kudos
Reply