Skip to content

resize function #15

@FrAllard

Description

@FrAllard

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions