InfiniTimeOrg / InfiniTime

Firmware for Pinetime smartwatch written in C++ and based on FreeRTOS
GNU General Public License v3.0
2.64k stars 907 forks source link

circularbuffer: Add circular buffer utility struct #1696

Closed FintasticMan closed 10 months ago

FintasticMan commented 1 year ago

Implements a simple circular buffer template. buf[0] is the value at the current index. You can use the ++ and -- operators to move the index. You can initialise the buffer using aggregate initialisation, meaning you can just initialise with a curly-brace list.

github-actions[bot] commented 1 year ago
Build size and comparison to main: Section Size Difference
text 409268B 0B
data 996B 0B
bss 63356B 0B
FintasticMan commented 1 year ago

I've just pushed a change that switches NotificationManager to use this new CircularBuffer. IMO it makes the code easier to understand from a glance.

Riksu9000 commented 1 year ago

Maybe a static sized vector class is more along the lines of what we need for NotificationManager, along with a helper function that will erase the oldest entry if pushing a new element wouldn't fit otherwise.

See #1712

FintasticMan commented 10 months ago

Merged with #826.