#include <libsswf.h>
Public Member Functions | |
Buffer (Buffer **head, MemBuffer *ptr, size_t size, const char *info) | |
Initialize this buffer with a preallocated buffer as defined in MemBuffer. | |
Buffer (Buffer **head, size_t size, const char *info) | |
Initialize a memory buffer. | |
void * | Data (void) const |
The Data() function returns the current data pointer allocated in this buffer. | |
const char * | Info (void) const |
Return the pointer of the static const string passed down to one of the functions used for this effect. | |
Buffer * | Next (void) const |
Returns a pointer to the next Buffer in a list of Buffers. | |
Buffer * | Previous (void) const |
Returns a pointer to the previous Buffer in a list of Buffers. | |
void * | Realloc (size_t size) |
Reallocate the buffer of memory. | |
size_t | Size (void) const |
Returns the size of the data buffer in bytes. This is the same size used to allocate the buffer. | |
~Buffer () | |
Unlink this buffer and free the attached memory. | |
Static Public Member Functions | |
static Buffer * | FindBuffer (void *ptr) |
Search for a Buffer given a data pointer. | |
Private Types | |
enum | { DMAGIC = (unsigned long) 0x53535746, OMAGIC = (unsigned long) 0x5353574F } |
Private Attributes | |
void * | f_data |
Buffer ** | f_head |
const char * | f_info |
Buffer * | f_next |
Buffer * | f_previous |
size_t | f_size |
Classes | |
struct | mem_buffer_t |
Hold the magic and a pointer to the actual buffer. More... |
It allocates and frees memory buffers and link all the buffers allocated in a memory manager.
If you need to handle a raw memory pointer in many different ways (including reallocating it) you may want to derive your class from the MemBuffer class and use that class to handle your buffer for you.
Buffer::Buffer | ( | Buffer ** | head, | |
size_t | size, | |||
const char * | info | |||
) |
This constructor saves the head pointer, the size and information about the buffer and then allocates a buffer of memory of the specified size.
head | A pointer to the f_head of the attached MemoryManager | |
size | The size of the buffer of memory to allocate | |
info | Information about this buffer (a static const string) |
References sswf::assert(), DMAGIC, sswf::Buffer::mem_buffer_t::f_buffer, f_data, f_head, f_info, sswf::Buffer::mem_buffer_t::f_magic, f_next, f_previous, f_size, SSWF_ALIGN, SSWF_SAFE, and SSWF_SPACE.
This constructor links a memory buffer to a buffer and a memory manager.
The size specifies the size of the buffer defined in the MemBuffer object.
The info is information about this buffer.
head | A pointer to the f_head variable of the memory manager to be attached to | |
ptr | A pointer to the memory buffer to reference in this buffer | |
size | The size of this buffer (should be sizeof(MemBuffer *)) | |
info | Information about this buffer (static const string) |
References sswf::assert(), sswf::MemBuffer::AttachBuffer(), sswf::Buffer::mem_buffer_t::f_buffer, f_data, f_head, f_info, sswf::Buffer::mem_buffer_t::f_magic, f_next, f_previous, f_size, OMAGIC, SSWF_SAFE, and SSWF_SPACE.
Buffer::~Buffer | ( | ) |
The destructor ensures that the buffer is unlinked also managing the f_head of the MemoryManager it is attached to.
Then it frees the memory allocated for the buffer of memory.
References sswf::assert(), DMAGIC, f_data, f_head, f_info, sswf::Buffer::mem_buffer_t::f_magic, f_next, f_previous, OMAGIC, SSWF_SAFE, and SSWF_SPACE.
sswf::Buffer::Data | ( | void | ) | const [inline] |
References f_data.
Referenced by sswf::MemoryManager::MemAlloc().
Buffer * Buffer::FindBuffer | ( | void * | ptr | ) | [static] |
This function searches for the Buffer object which references the specified data pointer.
The truth is that there is no search. Each data block allocated via a Buffer includes a pointer back to the corresponding buffer object. This is how it works and thus trying to find a Buffer from an invalid pointer will result in an assert() if not a crash.
ptr | The pointer of which you want the buffer object |
References sswf::assert(), DMAGIC, sswf::Buffer::mem_buffer_t::f_buffer, sswf::Buffer::mem_buffer_t::f_magic, OMAGIC, SSWF_SAFE, and SSWF_SPACE.
Referenced by sswf::MemoryManager::MemClean(), sswf::MemoryManager::MemFree(), sswf::MemoryManager::MemRealloc(), and sswf::MemoryManager::Size().
sswf::Buffer::Info | ( | void | ) | const [inline] |
sswf::Buffer::Next | ( | void | ) | const [inline] |
sswf::Buffer::Previous | ( | void | ) | const [inline] |
The first buffer has no previous buffer and NULL will be returned.
References f_previous.
void * Buffer::Realloc | ( | size_t | size | ) |
This function is used to change the size of the currently allocated buffer of memory.
The size should be positive. It can be larger or smaller than the current size.
A buffer allocated via a MemBuffer cannot be reallocated here.
size | The new buffer size |
References sswf::assert(), DMAGIC, f_data, sswf::Buffer::mem_buffer_t::f_magic, f_size, SSWF_ALIGN, SSWF_SAFE, and SSWF_SPACE.
Referenced by sswf::MemoryManager::MemRealloc().
sswf::Buffer::Size | ( | void | ) | const [inline] |
References f_size.
Referenced by sswf::MemoryManager::Size().
void* sswf::Buffer::f_data [mutable, private] |
Buffer** sswf::Buffer::f_head [private] |
const char* sswf::Buffer::f_info [private] |
Buffer* sswf::Buffer::f_next [private] |
Buffer* sswf::Buffer::f_previous [private] |
Referenced by Buffer(), Previous(), and ~Buffer().
size_t sswf::Buffer::f_size [private] |