Large Float Array

float readings[360];

Global variables use 1729 bytes (21%) of dynamic memory, leaving 6463 bytes for local variables. Maximum is 8192 bytes.

float readings[3600];

Not enough memory; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing your footprint.
data section exceeds available space in board
Error compiling for board Arduino Mega or Mega 2560.

What is the problem with this according to what I have found a 8k float array should work:

char a[ 32767 ];
short b[ 16383 ];
int c[ 16383 ];
long d[ 8191 ];
long long e[ 4095 ];
float f[ 8191 ];
double g[ 8191 ]; //double is the same size as float on AVR Arduino's

I testing it on mega but will be run on Atmega328P at the end.

Where did you find that and what means the list of various data types and dimensions you list?

8192 floats is gonna take 4 * 8192 bytes…

a7

a float or double on your MEGA uses up 4 bytes.
how many RAM bytes do you have ?

Where did you find this table? It's fairly useless because it's highly dependent on the board used.

A float needs 4 bytes each on an AVR. So this array needs 14400 bytes of ram.
Arduino Mega -> 8192 bytes of ram
Arduino UNO -> 2048 bytes of ram
None of theses boards can hold a float array of this size.

1 Like

Looks like a table that lists a maximum PROGMEM capacity of the Arduino Uno board depending on data type.
But you should note that the PROGMEM can't be used for variables, only for constants.

How did you come to this conclusion?

God bless google I presume its the first hit for arduino array max size: Arduino FAQ - What is the maximum number of elements an array can have

Anyway I need dynamic array. What does one do in this case? I guess I could go with unsigned int to save some space but I need 3600 elements in the array.

One moves to a more SRAM capable device.
Arduino Memory Guide | Arduino Documentation | Arduino Documentation

You can't allocate an array of such size on the atmega328 even if you would use single bytes.

you could move to an Arduino Due or an ESP32???

There has to be a smarter solution than just throwing hardware to the problem.

All my code needs to be doing is keep adding float data to an array every loop, if there is no data or zero data it needs to add zero, once the end of the array reached the code starts overwriting values in it from the beginning (not zeroing the array leaving everything in place, overwrite elements one by one when reached).

So array[360] works, I could create 10 arrays with 360 elements each and once an array's end is reached it automatically continues with array2. It seems adding more arrays don't increase the used memory. :partying_face:

on which planet do you live?

each element (data) requires a given number of bytes depending on the type of the data (4 bytes for a float)
to store data you need memory. 10 floats require 10 x 4 = 40 bytes
memory is defined by the hardware you chose. so there is a built-in limit to what you can have in RAM.

what are you doing with those arrays? why do you need to keep 3600 elements ?

1 Like

Are you kidding us?

1 Like

I guess the answer is in :partying_face:

trolling...

1 Like

Arraykis!

That gives the maximum array size supported by the compiler - arrays are limited to 32768 bytes for avr processors, because of the 16 bit addressing. Limits are further restricted by the physical memory of the processor.

If you want to keep the Arduino platform, your only solution is to add external RAM. Or, reconsider your program and make it use less RAM.

Do you meant "AVR platform"?
Arduino platform includes many types of boards with variety of RAM options. Take for example ESP32, Arduino Due or RPi Pico.

I suspect that a full and proper description of @defilerden's problem would allow suggestions for approaches that require somewhat less memory.

Only s/he can provide that.

a7