Made to Order Software Corporation Logo

libsswf: sswf::MemoryManager Class Reference

A garbage collector manager. More...

#include <libsswf.h>

Inheritance diagram for sswf::MemoryManager:

:ActionBranch :ActionCallFrame :ActionDictionary :ActionFunction :ActionGoto :ActionLabel :ActionPushData :ActionSetTarget :ActionStoreRegister :ActionStrictMode :ActionTry :ActionURL :ActionWaitForFrame :ActionWith :Data :Edges :Event :SoundInfo :TagBase :Vectors

List of all members.


Public Member Functions

void * MemAlloc (size_t size, const char *info)
 Allocate a new buffer of memory.
void MemAttach (MemBuffer *ptr, size_t size, const char *info)
 Attach a memory buffer to a manager.
void MemClean (void *ptr)
 Free a memory buffer and clean the holding pointer.
void MemFree (void *ptr)
 Free a memory buffer.
 MemoryManager (void)
 Initialize a memory manager object.
void * MemRealloc (void *ptr, size_t size, const char *info)
 Allocate or re-allocate a memory buffer pointer.
unsigned long Size (void *ptr)
 Return the current size of a buffer of memory.
char * StrCat (const char *s1, const char *s2)
 Concatenate two strings using a managed buffer.
char * StrDup (const char *string)
 Duplicate a string using a managed buffer.
virtual ~MemoryManager ()
 Delete all the memory buffers.

Private Attributes

Bufferf_head

Detailed Description

The MemoryManager class is used as a garbage collection for all the object derived from it. These objects will allocate memory buffers and attach them to the collection of buffers in their memory manager.

Then when the object is deleted, all the buffers are automatically deleted.

The sswf::MemoryManager uses the Buffer and sswf::MemBuffer classes to manage the buffers.

See also:
sswf::Buffer

sswf::MemBuffer


Constructor & Destructor Documentation

MemoryManager::MemoryManager ( void   ) 

This constructor initialize the memory manager by clearing the head of the memory buffers.

References f_head.

MemoryManager::~MemoryManager (  )  [virtual]

The destructor goes through the list of memory buffers allocated by the memory manager functions and delete them all.

References f_head.


Member Function Documentation

void * MemoryManager::MemAlloc ( size_t  size,
const char *  info 
)

void MemoryManager::MemClean ( void *  ptr  ) 

This function is a convenience function which (1) calls MemFree() on the specified pointer and then clears the pointer.

This is particularly useful to not have to do the cleaning of the pointer yourself.

        char *buf;

        buf = MemAlloc(123);
        ...
        if(some flag) {
                MemClean(&buf);

                // is equivalent to:
                //  MemFree(buf);
                //  buf = 0;
        }
        ...
        if(buf != 0) {
                ...
        }

Note:
The compilers have a problem with a 'void **' type here. Thus I use 'void *' which can look a bit confusing. Sorry about that!
Parameters:
ptr The pointer to the pointer to free

References sswf::assert(), and sswf::Buffer::FindBuffer().

Referenced by sswf::Data::GetString(), sswf::ActionFunction::ParseData(), sswf::TagProtect::ParseTag(), sswf::TagFrameLabel::ParseTag(), sswf::TagText::PreSave(), sswf::TagFont::PreSave2ndPass(), sswf::TagSceneFrameData::SetFileData(), sswf::TagImage::SetFilename(), sswf::TagImage::SetImage(), sswf::TagSceneFrameData::SetSceneFrameData(), and sswf::Vectors::SetSize().

void MemoryManager::MemFree ( void *  ptr  ) 

This function release the memory associated with the specified pointer.

Parameters:
ptr The pointer to the memory to release

References sswf::Buffer::FindBuffer().

Referenced by sswf::TagEditText::AddUsedString(), sswf::TagSound::LoadWaveFile(), sswf::TagEditText::PreSave(), sswf::TagMetadata::Save(), sswf::TagImage::Save(), sswf::TagHeader::Save(), sswf::TagHeader::SaveEncodedString(), sswf::TagImage::SaveJPEG(), sswf::TagMetadata::SetAuthor(), sswf::TagMetadata::SetCopyright(), sswf::TagFont::SetCopyright(), sswf::TagSound::SetData(), sswf::TagBinaryData::SetData(), sswf::TagMetadata::SetDescription(), sswf::TagFont::SetDisplayName(), sswf::TagProtect::SetEncodedPassword(), sswf::TagMetadata::SetFilename(), sswf::TagImport::SetFilename(), sswf::TagImage::SetFilename(), sswf::TagFrameLabel::SetFrameLabel(), sswf::ActionWaitForFrame::SetFrameName(), sswf::ActionGoto::SetFrameName(), sswf::ActionTry::SetIdentifier(), sswf::TagInfo::SetInfo(), sswf::TagBase::SetLabel(), sswf::ActionLabel::SetLabel(), sswf::ActionBranch::SetLabel(), sswf::TagMetadata::SetMetadata(), sswf::TagPlace::SetName(), sswf::TagFont::SetName(), sswf::ActionFunction::SetName(), sswf::TagHeader::SetOutputEncoding(), sswf::TagProtect::SetPassword(), sswf::TagMetadata::SetPublisher(), sswf::ActionSetTarget::SetTarget(), sswf::TagEditText::SetText(), sswf::TagMetadata::SetTitle(), sswf::TagMetadata::SetURL(), sswf::TagImport::SetURL(), sswf::ActionURL::SetURL(), sswf::TagEditText::SetUsedGlyphs(), and sswf::TagEditText::SetVariableName().

void * MemoryManager::MemRealloc ( void *  ptr,
size_t  size,
const char *  info 
)

This function is used to enlarge or reduce the size of a previously allocated buffer or to allocate a new buffer.

When ptr is set to NULL, it behaves like sswf::MemoryManager::MemAlloc().

When ptr is not NULL, then the function searches the buffer. If the buffer was not previously allocated by MemAlloc() or some similar function, then an assert(3) will be emited in debug mode. In release, the buffer will be assumed correct and you will corrupt your memory.

Parameters:
ptr The pointer to re-allocate
size The size of the new buffer
info Information about the buffer (a static const string)
Returns:
The pointer to the reallocated memory block

References sswf::Buffer::FindBuffer(), MemAlloc(), and sswf::Buffer::Realloc().

Referenced by sswf::Data::AdjustSize(), sswf::Data::GetString(), sswf::TagSound::LoadMP3File(), sswf::TagBinaryData::ParseTag(), and sswf::Vectors::SetSize().

unsigned long MemoryManager::Size ( void *  ptr  ) 

This function searches for the specified buffer and returns its size.

Parameters:
ptr The pointer of which the size is to be returned
Returns:
The size of the buffer pointed by that pointer

References sswf::Buffer::FindBuffer(), and sswf::Buffer::Size().

Referenced by sswf::TagText::DefineText().

char * MemoryManager::StrCat ( const char *  s1,
const char *  s2 
)

This function concatenates two strings into one. The new string buffer is allocated using the memory manager.

Parameters:
s1 The string to appear on the left
s2 The string to appear on the right
Returns:
The result is a pointer to the newly allocated string

References MemAlloc(), and StrDup().

Referenced by sswf::TagMetadata::Save().


Member Data Documentation


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


Generated on Wed Mar 18 15:13:58 2009 for libsswf by  doxygen 1.5.5