AceCommon
1.4.5
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) | |
Create an instance with an internal buffer of size on the heap. | |
~PrintStrN () | |
Delete the internal buffer on the heap. More... | |
![]() | |
size_t | write (uint8_t c) override |
Write a single character into the internal buffer. | |
size_t | write (const uint8_t *buf, size_t size) override |
Write the buf string of size into the internal buffer. | |
void | flush () override |
Clear the internal buffer. | |
const char * | cstr () const |
Return the NUL terminated c-string buffer. More... | |
const char * | getCstr () const |
Backwards compatible version of cstr(). More... | |
size_t | length () const |
Return the length of the internal c-string buffer. | |
Additional Inherited Members | |
![]() | |
PrintStrBase (uint16_t size, char *buf) | |
Constructor. More... | |
![]() | |
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 257 of file PrintStr.h.
|
inline |
Delete the internal buffer on the heap.
This object itself should never be created on the heap, so we don't need to make the destructor virtual.
Definition at line 267 of file PrintStr.h.