Skip to content

Latest commit

 

History

History
47 lines (39 loc) · 1.53 KB

README.org

File metadata and controls

47 lines (39 loc) · 1.53 KB

Array

Library Information

Name
Array
Version
1.2.1
License
BSD
URL
https://github.com/janelia-arduino/Array
Author
Peter Polidoro
Email
[email protected]

An array container similar to the C++ std::array, with some std::vector methods added. The maximum size is fixed as a template parameter, but the size is variable, like a vector. Values can be pushed and popped and the size adjusts accordingly. The data are stored internally as a statically allocated c style array. Care must be taken not to dereference an empty array or access elements beyond bounds.

This library is very similar to Vector, however Vector stores data externally, outside the container, and this library stores data internally. The pointer to the external memory causes the Vector container to use more memory than this container, but storing the data internally makes it necessary to use the maximum size as a class template parameter.

Array vs Vector

Array

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

Vector

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