|
| 1 | +#+TITLE: Array |
| 2 | +#+AUTHOR: Peter Polidoro |
| 3 | +#+EMAIL: peterpolidoro@gmail.com |
| 4 | + |
| 5 | +* Library Information |
| 6 | + - Author :: Peter Polidoro |
| 7 | + - License :: BSD |
| 8 | + |
| 9 | + An array container similar to the C++ |
| 10 | + [[http://www.cplusplus.com/reference/array/array/][std::array]], with |
| 11 | + some [[http://www.cplusplus.com/reference/vector/vector/][std::vector]] |
| 12 | + methods added. The maximum size is fixed as a template parameter, but |
| 13 | + the size is variable, like a vector. Values can be pushed and popped |
| 14 | + and the size adjusts accordingly. The data are stored internally as a |
| 15 | + statically allocated c style array. Care must be taken not to |
| 16 | + dereference an empty array or access elements beyond bounds. |
| 17 | + |
| 18 | + This library is very similar to |
| 19 | + [[https://github.com/janelia-arduino/Vector][Vector]], however Vector |
| 20 | + stores data externally, outside the container, and this library stores |
| 21 | + data internally. The pointer to the external memory causes the Vector |
| 22 | + container to use more memory than this container, but storing the data |
| 23 | + internally makes it necessary to use the maximum size as a class |
| 24 | + template parameter. |
| 25 | + |
| 26 | +* Array vs Vector |
| 27 | + |
| 28 | +** Array |
| 29 | + |
| 30 | + #+BEGIN_SRC C++ |
| 31 | +const int ELEMENT_COUNT = 5; |
| 32 | +Array<int,ELEMENT_COUNT> array; |
| 33 | +array.push_back(77); |
| 34 | + #+END_SRC |
| 35 | + |
| 36 | +** Vector |
| 37 | + |
| 38 | + #+BEGIN_SRC C++ |
| 39 | +const int ELEMENT_COUNT = 5; |
| 40 | +int storage_array[ELEMENT_COUNT_MAX]; |
| 41 | +Vector<int> vector(storage_array); |
| 42 | +vector.push_back(77); |
| 43 | + #+END_SRC |
| 44 | + |
| 45 | +* Library Examples |
| 46 | + |
| 47 | + [[./examples]] |
| 48 | + |
| 49 | +* Library Dependencies |
| 50 | + |
| 51 | + [[https://github.com/janelia-arduino/arduino-libraries][arduino-libraries]] |
0 commit comments