QBoard » Supporting Tech Stack » IOT » Vectors in Arduino

Vectors in Arduino

  • I am making a vector of "waypoints" on the Arduino. Each waypoint is an object. The Arduino will obviously need to store multiple waypoints for waypoint navigation. But instead of storing these waypoints in a standard preprogrammed array, the user will need to be able to add, remove waypoints and move them around. Unfortunately the Arduino does not offer a vector type as a built-in library.

    I am currently contemplating two options:

    1. In Container for objects like C++ 'vector'?, someone posted a general purpose library. It does not contain any index deletion, or movement operations. But it does contain some memory management strategies.

    2. I have used malloc, dealloc, calloc in the past. But I do not like that option at all, especially with classes. But is this a better option in my senario?

    Which one is a better path to go down?

      June 13, 2019 11:52 AM IST
    0
  • Standard C++ for Arduino might be an option. It lets you use the STL vector in Arduino.
      June 13, 2019 11:55 AM IST
    0
  • Sounds like you would want to implement a simple linked list. A linked list allows you to move objects (waypoints, in your case) around without the overhead associated with C++ vectors.

    Here's an implementation on GitHub.

      June 14, 2019 12:09 PM IST
    0