Hello guys today i am come up with an interesting and impotent topic for embedded system programming on micro-controller. As the Micro- controllers has small and limited memory described as
FLASH - A non-volatile memory that primarily stores the program’s instructions, and also any “constant” data values. In general, you only read from this memory, and it is only written when you download new code to the micro-controller.
RAM - It is a volatile memory that is the working data space for storing all variables whilst the program is running. In C, this is static variables, the heap, and the stack.
RAM is therefore much more scarce and valuable than FLASH, so it is worth understanding a little about the memory model to help make best use of the memory.
EEPROM - Some microcontrollers have special non-volatile memory that can be erased and written byte for byte rather than in blocks or sectors. This memory is typically used by the application to store special data or configuration. This memory requires special access by a peripheral and is not directly addressable.
C Memory Model
Heap Memory - This is used for dynamic memory allocation. When we create a new instance of an object using ‘new’, or if you allocate a block of memory using malloc and friends, you use memory in the heap.
Static/Global memory - Global and static memory are values that are allocated for the entire lifetime of the program.
If for some reason you have data that is fixed (such as a lookup table), you’d be much better off making sure the compiler can allocate it in FLASH to save valuable RAM space. In the previous example, we could use the C keyword “const” to tell the compiler the variable will never be changed.
Stack - The Stack is used to store types of variables that have a fixed lifetime based on how C programs run. It is a section of RAM that grows and shrinks as the program runs. When you call a function, its parameters and any variables you have defined in that function (which are not static) are stored on the stack.