ESP32 IDF. Will this table be placed in the SPI FLASH and read from it or it will be loaded to the RAM
Yes.
From the ESP-IDF Programming Guide:
DROM (data stored in flash)
By default, constant data is placed by the linker into a region mapped to the MMU flash cache. This is the same as the IROM (code executed from flash) section, but is for read-only data not executable code.
The only constant data not placed into this memory type by default are literal constants which are embedded by the compiler into application code. These are placed as the surrounding function’s executable instructions.
The DRAM_ATTR attribute can be used to force constants from DROM into the DRAM (Data RAM) section (see above).
Using the const
modifier in C/C++ code will tell the linker it's safe to leave the data in flash. The ESP32 compiler and linker are smart enough to do this automatically, so there's no need for macros like _F
or PROGMEM
that Arduino uses.
You can confirm this by building a simple program that declares a very large initialized array. The program will need to do something to the array so that the array doesn't get optimized out. Run it once with the array declared const
and have it output the free heap space. Run it again with the array not declared const
. The second time you should see a smaller amount of heap space available, with the array using the difference.