Hi,
I use an Arduino Mega2560 and I'm trying to save a vector in another vector with a higher dimension. For the first vector I use a struct for the elements.
#include <ArduinoSTL.h>
struct exstruct{
uint16_t exint;
float exfloat;
};
std::vector<exstruct> exvec = {{5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}, {5,0.5}};
std::vector<std::vector<exstruct>> exvecvec = {exvec};
void setup(){
Serial.begin(9600);
delay(1000);
Serial.println("Reached setup");
}
void loop(){
}
If the first vector is too big, the program won't reach the setup function and outputs some squares and a mirrored question mark. In this code I left one element too much.
If I don't put it in the second vector, it works fine. The size of both vectors has to be dynamic, so using an array doesn't work.
My guess is that the memory is full at this size, even though it just reports 34% of dynamic memory used.
I tried using a pointer, so that the second vector just saves the position of the first vector but sadly I didn't get that to work. I've never really worked with pointers, so if somebody is more experienced with them and can help me solve the problem with pointers I'd be grateful.
I also tried saving it to PROGMEM, but I that didn't work because of the dynamic size of the vectors.
Is there any other way to solve this problem?
Or is the memory not even the problem?