-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Hi,
I needed to able to set the size of the array while in the setup but the array had to be global... So I wrote a little void function to resize... It basically reset the array and resize the pointer... Which is what I needed I didn't care that it was a destructive resize... Anyway realloc should not be used too much it might get corrupted after a while... In my case I do it once in setup...
I have dip switches so the end user can select which averaging he wants for the displayed values...
Here is what I added, feel free to integrate it if you want...
template <class T> void Average<T>::resize(uint32_t size) { clear(); _size = size; _count = 0; _store = (T *)realloc(_store, sizeof(T) * size); _position = 0; // track position for circular storage _sum = 0; // track sum for fast mean calculation for (uint32_t i = 0; i < size; i++) { _store[i] = 0; } }