0

I want to define an unknown size for an array. However, I know that this cannot be done on the arduino. So what other methods do you suggest? I tried using vectors by downloading the library ArduinoSTL, but it doesnt work. (It only prints Serial.println(Signal); once, referring to the code in the pastebin link below)

Heres my code with vectors: https://pastebin.com/qBsRvk9Y

  • unknown size? the size of the MCU RAM is known and there are no concurrent programs, so declare a maximum possible array and you are good to go – Juraj Apr 3 '18 at 6:58
1

The vector is empty after its default constructor. And nothing was ever added into it in your code. So you can't use anything like idexing by vect[index] or method vect.at(index). And as there are no exceptions available, who knows what it does after the out of range call.

You should consider ring buffer instead, using dynamic memory is tricky on such constrained platforms. Even using Arduino's String class is often source of memory fragmentation and out of memory type errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.