libsswf: sswf::Buffer Class Reference

# sswf::Buffer Class Reference

Linked list of memory buffers for easy memory management. More...

`#include <libsswf.h>`

List of all members.

## 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...

## Detailed Description

The Buffer class is the placeholder of the memory pointers used inside the MemoryManager.

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.

See also:
  sswf::MemoryManager

  sswf::MemBuffer

## Member Enumeration Documentation

anonymous enum`[private]`

Enumerator:

  DMAGIC |
  OMAGIC |

## Constructor & Destructor Documentation

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.

Parameters:

  | 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.

Buffer::Buffer | ( | Buffer ** | head,
|  | MemBuffer * | ptr,
|  | size_t | size,
|  | const char * | info |
| ) |  |  |

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.

Parameters:

  | 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.

## Member Function Documentation

sswf::Buffer::Data | ( | void |  | ) | const`[inline]`

Returns:
  A pointer to the data memory buffer held by this Buffer object

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.

Parameters:

  | ptr | The pointer of which you want the buffer object

Returns:
  The corresponding buffer pointer

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]`

References f_info.

Referenced by sswf::MemBuffer::AttachBuffer().

sswf::Buffer::Next | ( | void |  | ) | const`[inline]`

The last buffer has no next buffer and NULL will be returned.

Returns:
  A Buffer pointer

References f_next.

sswf::Buffer::Previous | ( | void |  | ) | const`[inline]`

The first buffer has no previous buffer and NULL will be returned.

Returns:
  A Buffer pointer

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.

Parameters:

  | size | The new buffer size

Returns:
  The new data pointer

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]`

Note:
  The size can be zero.

Returns:
  The size of the data memory buffer

References f_size.

Referenced by sswf::MemoryManager::Size().

## Member Data Documentation

void* sswf::Buffer::f_data`[mutable, private]`

Referenced by Buffer(), Data(), Realloc(), and ~Buffer().

Buffer** sswf::Buffer::f_head`[private]`

Referenced by Buffer(), and ~Buffer().

const char* sswf::Buffer::f_info`[private]`

Referenced by Buffer(), Info(), and ~Buffer().

Buffer* sswf::Buffer::f_next`[private]`

Referenced by Buffer(), Next(), and ~Buffer().

Buffer* sswf::Buffer::f_previous`[private]`

Referenced by Buffer(), Previous(), and ~Buffer().

size_t sswf::Buffer::f_size`[private]`

Referenced by Buffer(), Realloc(), and Size().

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

- libsswf.h
- libsswf_memory.c++