A smart buffer management class that automatically handles memory allocation and deallocation. More...
#include <SAutoBuf.h>
Public Member Functions | |
| SAutoBuf () | |
| Default constructor. Initializes an empty buffer. | |
| SAutoBuf (size_t nElements) | |
| Constructor with initial buffer size. Allocates a buffer of the specified size. | |
| ~SAutoBuf () | |
| Destructor. Frees the allocated buffer if it was not externally attached. | |
| operator char * () const | |
| Conversion operator to char*. | |
| char * | operator-> () const |
| Arrow operator to access members of the managed buffer. | |
| const char & | operator[] (int i) const |
| Const array subscript operator. | |
| char & | operator[] (int i) |
| Array subscript operator. | |
| void | Attach (char *pBuf, size_t size) |
| Attaches an external buffer to the SAutoBuf object. The buffer will not be freed by the SAutoBuf object. | |
| char * | Detach () |
| Detaches the managed buffer from the SAutoBuf object. The caller is responsible for freeing the buffer using soui_mem_wrapper::SouiFree. | |
| char * | Allocate (size_t nElements) |
| Allocates a buffer of the specified size. If a buffer is already allocated, it will be freed first. | |
| size_t | size () |
| Returns the size of the managed buffer. | |
| void | Free () |
| Frees the managed buffer. The buffer will be set to nullptr after being freed. | |
A smart buffer management class that automatically handles memory allocation and deallocation.
Definition at line 17 of file SAutoBuf.h.
| SAutoBuf::SAutoBuf | ( | ) |
Default constructor. Initializes an empty buffer.
Definition at line 16 of file SAutoBuf.cpp.
| SNSBEGIN SAutoBuf::SAutoBuf | ( | size_t | nElements | ) |
Constructor with initial buffer size. Allocates a buffer of the specified size.
| nElements | The number of elements (bytes) to allocate. |
Definition at line 8 of file SAutoBuf.cpp.
| SAutoBuf::~SAutoBuf | ( | ) |
Destructor. Frees the allocated buffer if it was not externally attached.
Definition at line 21 of file SAutoBuf.cpp.
| char * SAutoBuf::Allocate | ( | size_t | nElements | ) |
Allocates a buffer of the specified size. If a buffer is already allocated, it will be freed first.
| nElements | The number of elements (bytes) to allocate. |
Definition at line 40 of file SAutoBuf.cpp.
| void SAutoBuf::Attach | ( | char * | pBuf, |
| size_t | size ) |
Attaches an external buffer to the SAutoBuf object. The buffer will not be freed by the SAutoBuf object.
| pBuf | Pointer to the external buffer. |
| size | Size of the external buffer. |
Definition at line 54 of file SAutoBuf.cpp.
| char * SAutoBuf::Detach | ( | ) |
Detaches the managed buffer from the SAutoBuf object. The caller is responsible for freeing the buffer using soui_mem_wrapper::SouiFree.
Definition at line 62 of file SAutoBuf.cpp.
| void SAutoBuf::Free | ( | ) |
Frees the managed buffer. The buffer will be set to nullptr after being freed.
Definition at line 26 of file SAutoBuf.cpp.
| SAutoBuf::operator char * | ( | ) | const |
Conversion operator to char*.
Definition at line 89 of file SAutoBuf.cpp.
| char * SAutoBuf::operator-> | ( | ) | const |
Arrow operator to access members of the managed buffer.
Definition at line 83 of file SAutoBuf.cpp.
| char & SAutoBuf::operator[] | ( | int | i | ) |
Array subscript operator.
| i | Index of the element to access. |
Definition at line 71 of file SAutoBuf.cpp.
| const char & SAutoBuf::operator[] | ( | int | i | ) | const |
Const array subscript operator.
| i | Index of the element to access. |
Definition at line 77 of file SAutoBuf.cpp.
| size_t SAutoBuf::size | ( | ) |
Returns the size of the managed buffer.
Definition at line 35 of file SAutoBuf.cpp.