[Basic] C program and SRAM, flash, stack, heap ... Why microcontrollers use different types of memory like that?
Preface
When you build the source code in C/C++, you might see some output messages as the blow:
Flash used: 1166 of 262144 bytes (0.4%).
SRAM used: 2505 of 65536 bytes (3.8%). Stack: 2048 bytes. Heap: 128 bytes.
--------------- Rebuild Succeeded: 10/01/2024 17:46:40 ---------------
Figure 1: The output message from PSoC Creator |
Figure 2: The output message from Arduino IDE |
Have you asked yourself what are technical jargon such as flash, stack, and heap?
In short, they are kinds of memory for machines.
Microcontrollers use different types of memory (Flash, SRAM, EEPROM, etc.) because each type serves a specific purpose, balancing factors like cost, speed, power consumption, and data persistence.
Key Differences Between These Memory Types:
The explanation for the output message in the figure 1:
Flash used: 1222 of 262144 bytes (0.5%)
The program's code occupies 1222 bytes of the total available 262144 bytes in Flash memory. This is a very small portion, showing efficient memory usage
SRAM used: 2521 of 65536 bytes (3.8%)
The program's data consumes 2521 bytes out of 65536 bytes of SRAM (Static Random-Access Memory). This includes global variables and dynamically allocated memory.
Stack: 2048 bytes
The stack, which is used for function calls, local variables, and return addresses, is allocated 2048 bytes.
Heap: 128 bytes
The heap, used for dynamic memory allocation (via malloc or similar functions), is set to 128 bytes.
How do we match which part of the source code to which memory?
Let's dive into the following example:
To be continue
Comments
Post a Comment