AceUtils  0.2
Useful Arduino utilties which are too small for separate libraries.
Public Member Functions | List of all members
print_str::PrintStrN Class Reference

An alternate implementation of PrintStr that allocates the character array in the heap, instead of the stack. More...

#include <PrintStr.h>

Inheritance diagram for print_str::PrintStrN:
Inheritance graph
[legend]
Collaboration diagram for print_str::PrintStrN:
Collaboration graph
[legend]

Public Member Functions

 PrintStrN (uint16_t size)
 
- Public Member Functions inherited from print_str::PrintStrBase
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

- Protected Member Functions inherited from print_str::PrintStrBase
 PrintStrBase (uint16_t size, char *buf)
 
- Protected Attributes inherited from print_str::PrintStrBase
char *const buf_
 This is the pointer to the character array buffer. More...
 

Detailed Description

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.


The documentation for this class was generated from the following file: