Size of array too large error message

Hi

I am making a project with Arduino and I want to declare an array with 1,400,000 spots.The compiler spits aout an error message "size of array is too large".It is crucial for my project to hve that big array.

Does anyone know how can I do that?
Any help is appreciated.

You're working with parts that have a few thousand bytes of RAM. If you need storage of 3 orders of magnitude more data, you're going to need to look at external means like an SPI EEPROM or SD card or some such.

ARIS009:
Hi

I am making a project with Arduino and I want to declare an array with 1,400,000 spots.The compiler spits aout an error message "size of array is too large".It is crucial for my project to hve that big array.

Does anyone know how can I do that?
Any help is appreciated.

Compare that number to the available memory in an Arduino. what do you get?

Paul

What are you putting in the array and why so many elements ?

It'd be interesting to know the definition of a memory 'spot'.

Thanks for the answers.

I am sure the arduino can do such thing because I was able to declare 47 arrays with a size of 30,000
each(47*30,000 = 1,400,000)(all the arrays are of type byte).So I do not need any external memory.I just do not know how to declare one array of size 1,400,000.

ARIS009:
I am sure the arduino can do such thing because I was able to declare 47 arrays with a size of 30,000
each(47*30,000 = 1,400,000)(all the arrays are of type byte).So I do not need any external memory.I just do not know how to declare one array of size 1,400,000.

That is absolute nonsense! I don't know of any Arduino with anywhere near that much memory. There is NO way you actually got such code to compile. More likely the compiler optimized the arrays out because you never referenced them.
Regards,
Ray L.

AVR-GCC is limited to arrays shorter than 32k bytes (which is a bit academic unless you add external RAM, since the largest AVR only has 16k bytes of RAM.)

Which Arduino are you using? I guess a Yun might have 1.4Mbyte+ of RAM, but ... that's the only one.

Of course, you can define very large automatic arrays (up to the limit for an individual array) in huge numbers, and the compiler will not complain, however, if the run time call sequence is such that multiple huge arrays must be present simultaneously, you get a problem.

I am sure the arduino can do such thing because ......

because you don’t understand what you are doing.

It is crucial for my project to hve that big array.

Then your project will never work.

For the ones that do not believe me here is my full code. You can try to compile it yourselfs.

Also if you can't help then simply don't post.

sampler.ino (8.45 KB)

#define input A0

boolean num[47];
int counter = 1;

byte Samples1[30000];
byte Samples2[30000];
byte Samples3[30000];
byte Samples4[30000];
byte Samples5[30000];
byte Samples6[30000];
byte Samples7[30000];
byte Samples8[30000];
byte Samples9[30000];
byte Samples10[30000];
byte Samples11[30000];
byte Samples12[30000];
byte Samples13[30000];
byte Samples14[30000];
byte Samples15[30000];
byte Samples16[30000];
byte Samples17[30000];
byte Samples18[30000];
byte Samples19[30000];
byte Samples20[30000];
byte Samples21[30000];
byte Samples22[30000];
byte Samples23[30000];
byte Samples24[30000];
byte Samples25[30000];
byte Samples26[30000];
byte Samples27[30000];
byte Samples28[30000];
byte Samples29[30000];
byte Samples30[30000];
byte Samples31[30000];
byte Samples32[30000];
byte Samples33[30000];
byte Samples34[30000];
byte Samples35[30000];
byte Samples36[30000];
byte Samples37[30000];
byte Samples38[30000];
byte Samples39[30000];
byte Samples40[30000];
byte Samples41[30000];
byte Samples42[30000];
byte Samples43[30000];
byte Samples44[30000];
byte Samples45[30000];
byte Samples46[30000];
byte Samples47[30000];
//---------------------------------------------------


void setup() {
  Serial.begin(9600);
  pinMode(input,INPUT);
  rec();
}
void loop(){
}

void rec() {
  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples1[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples2[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples3[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples4[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples5[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples6[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples7[i] = analogRead(input) / 4;
    }
  }


  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples8[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples9[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples10[i] = analogRead(input) / 4;
    }
  }
  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples11[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples12[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples13[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples14[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples15[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples16[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples17[i] = analogRead(input) / 4;
    }
  }


  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples18[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples19[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples20[i] = analogRead(input) / 4;
    }
  }
  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples21[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples22[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples23[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples24[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples25[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples26[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples27[i] = analogRead(input) / 4;
    }
  }


  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples28[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples29[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples30[i] = analogRead(input) / 4;
    }
  }
  
  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples31[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples32[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples33[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples34[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples35[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples36[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples37[i] = analogRead(input) / 4;
    }
  }


  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples38[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples39[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples40[i] = analogRead(input) / 4;
    }
  }
  
  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples41[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples42[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples43[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples44[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples45[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples46[i] = analogRead(input) / 4;
    }
  }

  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples47[i] = analogRead(input) / 4;
    }
  }
  counter = 1;
}

@OP - what were you thinking?

ARIS009:
For the ones that do not believe me here is my full code. You can try to compile it yourselfs.

Also if you can't help then simply don't post.

You've got to be joking, right?

If you declare variables then do nothing with them the compiler/linker acts like they don't exist.

I edited your sketch to store just one of your giant arrays, then print out at the end. I ran out of memory.

How do you get on?

#define input A0

boolean num[47];
int counter = 1;

byte Samples1[30000];

//---------------------------------------------------


void setup() {
  Serial.begin(9600);
  pinMode(input, INPUT);
  rec();
}
void loop() {
}

void rec() {
  if (true) {
    num[counter] = true;
    ++counter;
    for (int i = 0; i < 30000; ++i) {
      Samples1[i] = analogRead(input) / 4;
    }
  }

  counter = 1;

  // now let's use some of that data

  for (int i = 0; i < 30000; ++i) {
    Serial.println(Samples1[i]);
  }
}

ARIS009:
For the ones that do not believe me here is my full code. You can try to compile it yourselfs.

Also if you can't help then simply don't post.

And what you actually compiled is approximately this:

#define input A0

void setup() {
  Serial.begin(9600);
  pinMode(input,INPUT);
}
void loop(){
}

You fill all those arrays. but never do anything with them. So, the compiler is smart enough to realize the arrays serve no useful purpose, and optimizes them away.

Don't believe me? Add a single loop that READS one of those arrays, and prints it to the Serial Console. THAT code will NOT compile, and the compiler will tell you there is not enough memory.

You really do not understand nearly as much as you seem to believe you do. What you are attempting to do will NEVER work on an Arduino.

Regards,
Ray L.

ARIS009:
For the ones that do not believe me here is my full code. You can try to compile it yourselfs.

c:/users/sterretje/appdata/local/arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld.exe: address 0x9586b9 of C:\Users\sterretje\AppData\Local\Temp\arduino_build_528596/sketch_jan16a.ino.elf section `.bss' is not within region `data'

c:/users/sterretje/appdata/local/arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld.exe: address 0x9586b9 of C:\Users\sterretje\AppData\Local\Temp\arduino_build_528596/sketch_jan16a.ino.elf section `.bss' is not within region `data'

[b][color=red]collect2.exe: error: ld returned 1 exit status[/color][/b]

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

IDE 1.8.5, board manager 1.6.21

ARIS009:
For the ones that do not believe me here is my full code. You can try to compile it yourselfs.

So that will be everyone then. You have not had a single reply that says you can do this.

Also if you can't help then simply don't post.

Also if you are not prepared to learn then we would appreciate it if you don't post either. We are prepared to help but you are not prepared to be helped.