- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi
in nios software, after i build it, the message shows: Info: (vi23_swprj.elf) 23 KBytes program size (code + initialized data). Info: 6764 Bytes free for stack + heap. how much space should i give to the stack + heap? how could i decide the stack + heap size?Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The required stack and heap size strongly depend on what your code does and how it is structured.
Stack size usually increase if you use many levels of function calls (main calls fn1 which calls fn2 which calls fn3...) and/or if you use a lot of local variables. This is because each function call pushes some data on the stack, i.e. function parameters, return address, local variables: then the stack grows momentarily until the function returns. More nested calls you have, more the stack will grow. For the same reason the grow could be 'explosive' if you use recursive calls. Heap size substantially depends on manually allocated variables. If your code doesn't use functions like malloc or calloc, you virtually don't need heap at all. Clearly, you must also consider any library functions you are using. They will add some stack -and possibly heap- usage to that stricly required by your code.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thank you Cris72
so if the stack + heap is not big enough, will the eclipse give me some warnings?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
AFAIK you'll get no warnings.
The compiler can hardly infer from your code how much space is actually required.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Most likely the stack will crash into the heap and all hell will break loose.
Maximum stack use is likely to be in some obscure error path. Maximumum heap use is likely to happen due to heap fragmentation. In reality, unless you have a lot of spare memory (so it just isn't going to be a problem), you don't want to be using heap allocated memory (certainly not after any initialisation phase). My nios code (which implements a hdlc and a protocol over it) is carfully written so that the compiler can inline all function calls and never uses the stack at all (ok, there is still some function prologue that saves registers on the stack).- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you are really concerned about stack, you should check the "enable_runtime_stack_checking" option at the nios2-bsp-editor (Main>>Advanced>>hal).
This however can increase code size but at least will guarantee stack corruption does not occur.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page