Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resize function #15

Open
FrAllard opened this issue Jun 29, 2017 · 1 comment
Open

resize function #15

FrAllard opened this issue Jun 29, 2017 · 1 comment

Comments

@FrAllard
Copy link

FrAllard commented Jun 29, 2017

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; } }

@majenkotech
Copy link
Contributor

That's awesome. I'll add it to the main code when I get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants