AceCommon
1.1
Arduino library for low-level common functions and features with no external dependencies
|
An alternate implementation of PrintStr
that allocates the character array in the heap, instead of the stack.
More...
#include <PrintStr.h>
Public Member Functions | |
PrintStrN (uint16_t size) | |
![]() | |
size_t | write (uint8_t c) override |
size_t | write (const uint8_t *buf, size_t size) override |
void | flush () override |
const char * | getCstr () const |
Return the NUL terminated c-string buffer. More... | |
size_t | length () const |
Return the length of the internal c-string buffer. | |
Additional Inherited Members | |
![]() | |
PrintStrBase (uint16_t size, char *buf) | |
![]() | |
char *const | buf_ |
This is the pointer to the character array buffer. More... | |
An alternate implementation of PrintStr
that allocates the character array in the heap, instead of the stack.
This allows the creation of PrintStr
which are much larger than the available stack size. For an ESP8266 for example, the maximum stack size is about 4kB, even though there is 80kB of static RAM available.
The name PrintStrN
was the best I could think of that was relatively short, similar to PrintStr
, and conveyed the idea that the memory is allocated on the heap, which allows the size
parameter to be a runtime value, instead of a compile-time value.
If this object is created dynamically at the beginning of a function, the character array buffer will be created on the heap. At the end of the function, the object will be automatically destroyed, and destruuctor will automatically reclaim the character array on the heap. If no other heap allocation is performed, then this object should cause no heap fragmentation, just like the PrintStr
object which uses only the stack.
Definition at line 246 of file PrintStr.h.