-
Notifications
You must be signed in to change notification settings - Fork 7.7k
code is too big #11541
-
Board
ESP32-S3
Device Description
ESP32-S3-Korvo-2
Hardware Configuration
no
Version
latest stable Release (if not listed below)
IDE Name
Arduino IDE
Operating System
Windows 11
Flash frequency
240MHz
PSRAM enabled
yes
Upload speed
115200
Description
I need to use a big unsigned char array,but the Arduino IDE compile not passed because the array is too big.How can i solve this problem?
The array has 4M elements.
Sketch
Bandwidth exhausted or memory limit exceeded
Debug Message
no
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
I need to use a big unsigned char array,but the Arduino IDE compile not passed because the array is too big.How can i solve this problem?
The array has 4M elements.
Is it an immutable type of data, meaning that the bytes won't change along the execution of the application?
In such case it can be stored in the Flash, by declaring it as
const char Array[4 * 1024 * 1024] = { byte1, bytes2, ... , byte4194304 };
It is also necessary to correctly set the Partition Scheme to have an application partition that can store the firmware size plus the 4MB data.
Otherwise, if the data must be allocated to RAM, it shall go to a PSRAM sized to store such volume of data.
Declaration shall be something like:
char *bigArray = NULL; void setup() { bigArray = (char *) malloc(4 * 1024 * 1024); if (bigArray == NULL) { log_e("Memory allocation in PSRAM has failed."); } // populating the array with sequence values for (uint32_t i = 0; i < 4 * 1024 * 1024; i++) { bigArray[i] = (char) i & 0xFF; } }
Beta Was this translation helpful? Give feedback.