Buffer class maintains an allocated chunk of memory. It takes care of freeing the memory when the object goes out of scope. It uses malloc/free/realloc. It can also read a file into the buffer.
#include <util.h>
Public Member Functions | |
| void * | ptr () |
| const void * | cptr () |
| size_t | size () const |
| void | alloc (size_t size) |
| void | reAlloc (size_t size) |
| void | free () |
| void | copyFrom (Buffer &src) |
| void | moveFrom (Buffer &src) |
| bool | readFile (const char *filename, bool nullterm) |
| void jvar::Buffer::alloc | ( | size_t | size | ) |
| void jvar::Buffer::copyFrom | ( | Buffer & | src | ) |
| const void* jvar::Buffer::cptr | ( | ) | [inline] |
Returns a const pointer to the memory
| void jvar::Buffer::free | ( | ) |
Frees the memory
Referenced by alloc(), jvar::BArray::clear(), moveFrom(), readFile(), reAlloc(), and jvar::BArray::useFixedMem().
| void jvar::Buffer::moveFrom | ( | Buffer & | src | ) |
| void* jvar::Buffer::ptr | ( | ) | [inline] |
Returns a pointer to the memory
Referenced by copyFrom(), and readFile().
| bool jvar::Buffer::readFile | ( | const char * | filename, |
| bool | nullterm | ||
| ) |
Reads a file into the buffer
| filename | Name of the file to read |
| nullterm | If True, add a '\0' so the buffer can be used as a null-terminated string |
| void jvar::Buffer::reAlloc | ( | size_t | size | ) |
Realocates the buffer to be the new size. realloc() semantics are used.
| size | New size in bytes |
References free(), and size().
Referenced by copyFrom(), and readFile().
| size_t jvar::Buffer::size | ( | ) | const [inline] |
Returns the size of the buffer
Referenced by alloc(), copyFrom(), and reAlloc().