iam new to C and experienced with assembly language programming.
Typically in embedded C, which data is stored in heap?
If there are various threads/process like ADC, communication etc..when switching between different process where is the data being stored (stack or heap).
From where is this space for stack or heap allocated. Is it in RAM or elsewhere?
Data that is local to functions is stored on the stack, and each thread (i.e. task) has it's own stack space.
The heap is there for applications programs that need to allocate objects at run-time whose lifetime isn't synchronized to any particular sequence of function calls, or even objects whose 'ownership' passes from one task to another.
Having said that, using the heap is usually frowned upon in an embedded system that has any pretense at all of being mission-critical.
Do a web search on stack, heap and heap fragmentation. You should find _something_ out there.
--
Tim Wescott
Control systems and communications consulting
http://www.wescottdesign.com
Need to learn how to apply control theory in your embedded system?
"Applied Control Theory for Embedded Systems" by Tim Wescott
Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
Nonsense. The heap user may be untrustworthy, though. For example, using the initialization routine to allocate a set of buffers, etc. from the heap, via malloc, is perfectly safe. The system just ceases allocation when enough buffers are present, or the malloc refuses. From thereon the malloc/free/realloc system can go unused.
Alternatively the programmer simply provides a reliable way to handle malloc refusal. This may involve releasing previously allocated memory. It is up to the programmer to ensure that this is always feasible.
--
Chuck F (cbfalconer at maineline dot net)
Try the download section.
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.