SkillAgentSearch skills...

TinyCStringBuilder

Fast snprintf replacement for embedded+ use. Header only C++11 lib

Install / Use

/learn @DraTeots/TinyCStringBuilder
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

TinyStringBuilder

C strings builder - sprintf replacement for embedded use.

Header only library written in C++11 aimed for embedded usage. Faster than sprintf.

  • No dynamic memory allocations & minimal memory foorprint
  • C string safe
  • Faster than sprintf family
  • Floating point support (which can be switched off)
  • Control over features to build (make it tiny for tiny devices)
  • Follow fixed size stdint type family (uint8_t, int16_t, ...)
  • No std library dependence

Developed with thought of tiny or no-OS embedded applications, where dynamic memory allocations are not advisable and C++ std:: library is not appliable.

Exameple

char buffer[100];

CStringBuilder cb(buffer);    // Create cstring builder, give it the buffer
 
cb << "hello world! x = " << 5; // Use << operator overloads
cb.add(5);                      // or do it by hand

puts(cb.cstr());              // Use cstr() to get buffer pointer
if(cb.size()) ...             // Use size() to get actual string size
if(cb.buffer_size()) ...      // Get initial buffer size

Floating point

// Set TCSB_USE_FP 1

cb.addf(4.545) ;
// or
cb << 4.545;

Integer and floating point promotions have the same rank and integer and floating point conversions have the same rank (more here). So we have to use addf for floats

Future optimisation

First, needless to say that even strnlen can be implemented with a lot of black magic to perform faster. No doubts this project can be implemented partly in asm + #ifdefs to particular architectures so that it is even faster.

Related Skills

View on GitHub
GitHub Stars7
CategoryDevelopment
Updated1y ago
Forks1

Languages

C

Security Score

70/100

Audited on Aug 21, 2024

No findings