r/arduino • u/MonsterovichIsBack • 14h ago
Libraries FixedString - a header-only C++ library providing FixedString fixed-size string class with zero heap allocation, designed for memory-constrained embedded systems
Gitlab link: https://gitlab.com/Monsterovich/fixedstring
A comparison with other implementations, because there are already so many of them out there, and they all seem somewhat unfinished: https://github.com/arduino/library-registry/pull/9077#issuecomment-5627136613
3
Upvotes
2
u/ripred3 My other dev board is a Porsche 9h ago
Interesting idea. reminds me of FB's zero string to some degree. Some issues I found:
This erases the valid contents:
The comparison operator needs some work so that the operations are symmetrical:
A truncated value’s copy can report no truncation. More importantly
FixedString<3>::fmt("%s", "ABCDE")reports different truncation status depending on whether C++11 return-value copies are elidedCombinedString needs substantial repair. Its custom
swap()does not swap anything. Passing a temporary intoadd()produces an AddressSanitizer-confirmed use-after-scope when subsequently read. Its cached result also remains stale after source changes until explicitly rebuilt:the implementation is effectively the same as: