heap memory in C

Thread Starter

cktcrazy

Joined Mar 27, 2011
16
hello

i have some doubt about heap memory. i know when we allocate memory at runtime i.e.dynamically the memory allocated in the heap area.i am a firmware programmer workin in C. is memory allocation is required when we are working on some operating system because in firmware we directly write program and dump the hex file in target hardware ?????? here we don't have any heap memory area in microcontroller or something like heap momory area is there in RAM . i'm bit confused......... i guess no........

plz help me in this regard
waiting for your response

regards
cktcrazy
 

debjit625

Joined Apr 17, 2010
790
Heap memory also called free store is nothing more that a logical memory mapping in system's memory,you can create heap in microcontroller's RAM region but its useless in microcontroller because heap memory is normally related to a large chunk of memory allocated at runtime and microcontrollers have really very small amount of memory and normally they are not used to run Real Time Operating System(not large enough to support dynamic memory allocation) ,thats the job for microprocessor where we connect external memory and that makes it large enough.

Good luck
 

mjhilger

Joined Feb 28, 2011
118
What he said! Seriously, if you are going to program in C for microcontrollers, you better get used to looking over the assembly and/or the mem map created by the compiler to understand its memory usage. Each compiler operates a little different and especially on microcontrollers with the very limited memory, they play a lot of tricks to squeeze efficiency out. Malloc is not a good use of memory in uC. If you write a few very simple "C" programs and then spend an evening looking at [the dump of your program] each assembly command that was used to implement your program, you will get to see how that compiler is using the memory and registers. It can help you write better/faster code to understand the implementation.
 
Top