janelia-arduino / Vector

A sequence container similar to the C++ std::vector, but instead of allocating memory dynamically, this container points to an external, statically allocated c style array.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vector

Library Information

Name
Vector
Version
1.2.2
License
BSD
URL
https://github.com/janelia-arduino/Vector
Author
Peter Polidoro
Email
peter@polidoro.io

A sequence container similar to the C++ std::vector, but instead of allocating memory dynamically, this container points to an external, statically allocated c style array. The maximum size is fixed at compile time, but the size can change by pushing and popping elements from the vector. Static memory allocation is used to avoid dynamic allocation problems on very small embedded processors. Care must be taken not to dereference an empty vector, access elements beyond bounds, or use without setting the storage array.

This library is very similar to Array, however Array stores data internally in the container and this library stores data externally. The pointer to the external memory causes this container to use more memory than the Array container, but storing the data externally avoids needing the maximum size as a class template parameter.

Vector vs Array

Vector

const int ELEMENT_COUNT_MAX = 5;
int storage_array[ELEMENT_COUNT_MAX];
Vector<int> vector(storage_array);
vector.push_back(77);

Array

const int ELEMENT_COUNT_MAX = 5;
Array<int,ELEMENT_COUNT_MAX> array;
array.push_back(77);

About

A sequence container similar to the C++ std::vector, but instead of allocating memory dynamically, this container points to an external, statically allocated c style array.

License:Other


Languages

Language:C++ 100.0%