Increase Code Size with const arrays

joepasquariello

Well-known member
I needed large hex files for testing on T3.x, and used this approach to increase code size. Thought I'd share in case anyone can use such a thing. Is there a shorter/easier method?

//nested arrays of integers to initialize multi-dimensional variable(s)
#define A0 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15} // 64 bytes
#define A1 {A0,A0,A0,A0,A0,A0,A0,A0,A0,A0,A0,A0,A0,A0,A0,A0} // 64*16 = 1K
#define A2 {A1,A1,A1,A1,A1,A1,A1,A1,A1,A1,A1,A1,A1,A1,A1,A1} // 1K*16 = 16K

// const variables reside in flash and get optimized out if never accessed
const uint32_t KB128[8][16][16][16] = { A2, A2, A2, A2, A2, A2, A2, A2 };

void setup() {
// access const array to include in code, or comment out to remove
while (!Serial) {}
for (int i=0; i<16; i++) Serial.print( KB128[0] );
Serial.println();
}

void loop() {
}
 
Back
Top