For some libraries I want to use, my ESP32 does not have enough heap memory available, so I need to freeze the module in order to store it in the ROM and thus save RAM.
I've searched the internet for a good tutorial but with no success (all was to advanced or not specific enough).
I hope you can point me to a relevamt tutorial or respond with the overall guidelines.
I work in a windows environment.
Thanks in advance
Freeze modules into ROM
-
- Posts: 9725
- Joined: Thu Nov 26, 2015 4:08 am
Re: Freeze modules into ROM
Arduino nor ESP32 has the concept of 'freezing a module into ROM'; you'll need to be a bit more clear on what exactly you mean with that and why you think it's a solution for your running-out-of-heap issue.
-
- Posts: 826
- Joined: Mon Jul 22, 2019 3:20 pm
Re: Freeze modules into ROM
Tips for memory management:
1) Don't pass objects between functions. Passing objects (especially String) between functions will make copies that are unlikely to be destroyed after use. Pass pointers. Using pointers is fundamental to C programming.
2) const objects are mapped directly from ROM, so are only taken into memory when used. This can be done explicitly (const char* indexHtml = "<html><body>yadayada</body></html>") or in passing (printf "String stored in ROM data1: %d\tdata2: %s\n", data1, data2).
3) The builtin modules generally can be unloaded. BLE and WiFi both have deinit functions (you need to turn it off first).
4) Use NimBLE rather than the builtin BLE. It will use less ROM and RAM (https://github.com/h2zero/NimBLE-Arduino)
5) If you really need more memory, psram-equipped modules cost about $0.35 more. How much is your time worth?
6) Look for your leaks. I use this code in Arduino, and then call MEMCK around code where I want to monitor memory.
1) Don't pass objects between functions. Passing objects (especially String) between functions will make copies that are unlikely to be destroyed after use. Pass pointers. Using pointers is fundamental to C programming.
2) const objects are mapped directly from ROM, so are only taken into memory when used. This can be done explicitly (const char* indexHtml = "<html><body>yadayada</body></html>") or in passing (printf "String stored in ROM data1: %d\tdata2: %s\n", data1, data2).
3) The builtin modules generally can be unloaded. BLE and WiFi both have deinit functions (you need to turn it off first).
4) Use NimBLE rather than the builtin BLE. It will use less ROM and RAM (https://github.com/h2zero/NimBLE-Arduino)
5) If you really need more memory, psram-equipped modules cost about $0.35 more. How much is your time worth?
6) Look for your leaks. I use this code in Arduino, and then call MEMCK around code where I want to monitor memory.
- const char* fmtMemCk = "Free: %d\tMaxAlloc: %d\t PSFree: %d\n";
- #define MEMCK Serial.printf(fmtMemCk,ESP.getFreeHeap(),ESP.getMaxAllocHeap(),ESP.getFreePsram())
Who is online
Users browsing this forum: No registered users and 76 guests