#include <libsswf.h>
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 | |
Buffer * | f_head |
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.
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.
void * MemoryManager::MemAlloc | ( | size_t | size, | |
const char * | info | |||
) |
The memory manager allocates a new buffer and returns the pointer to the data of the buffer.
Note that the allocation of the sswf::Buffer object is hidden from view.
size | Size of the memory block to allocate | |
info | Information about the buffer (a static const string) |
References sswf::Buffer::Data(), and f_head.
Referenced by sswf::TagText::AddText(), sswf::TagEditText::AddUsedString(), sswf::TagText::DefineText(), sswf::Data::GetString(), sswf::TagImage::LoadJPEG(), sswf::TagImage::LoadTGA(), sswf::TagSound::LoadWaveFile(), MemRealloc(), sswf::TagFrameLabel::ParseTag(), sswf::TagEditText::PreSave(), sswf::TagFont::PreSave2ndPass(), sswf::TagMetadata::Save(), sswf::TagImage::Save(), sswf::TagHeader::Save(), sswf::TagHeader::SaveEncodedString(), sswf::TagImage::SaveJPEG(), sswf::TagSound::SetData(), sswf::TagBinaryData::SetData(), sswf::TagSceneFrameData::SetFileData(), sswf::TagSceneFrameData::SetSceneFrameData(), sswf::TagEditText::SetUsedGlyphs(), StrCat(), and StrDup().
void MemoryManager::MemAttach | ( | MemBuffer * | ptr, | |
size_t | size, | |||
const char * | info | |||
) |
This function takes the specified memory buffer under control.
This means it will delete the buffer whenever the object is deleted or when MemFree() is called.
ptr | The pointer to take control over | |
size | The size of the buffer pointed by ptr | |
info | Information about the buffer (a static const string) |
References f_head.
Referenced by sswf::ActionPushData::AddBoolean(), sswf::ActionPushData::AddDouble(), sswf::TagShape::AddEdge(), sswf::SoundInfo::AddEnvelope(), sswf::ActionPushData::AddFloat(), sswf::TagFont::AddGlyph(), sswf::ActionPushData::AddInteger(), sswf::TagFont::AddKern(), sswf::ActionPushData::AddLookup(), sswf::TagShape::AddMove(), sswf::TagImport::AddName(), sswf::ActionPushData::AddNull(), sswf::ActionFunction::AddParameter(), sswf::ActionPushData::AddRegister(), sswf::ActionPushData::AddString(), sswf::ActionDictionary::AddString(), sswf::TagShape::AddStyle(), sswf::TagText::AddText(), sswf::ActionPushData::AddUndefined(), sswf::Action::FindLabelAtOffset(), sswf::TagShape::NewEdges(), sswf::TagShape::NewSetup(), sswf::TagShape::NewStyles(), sswf::ActionPushData::ParseData(), sswf::ActionDictionary::ParseData(), sswf::TagExport::ParseTag(), sswf::TagButton::ParseTag(), sswf::TagText::RecordSetup(), sswf::Edges::Set(), sswf::TagDoAction::SetAction(), sswf::TagButton::SetAction(), sswf::TagExport::SetObject(), and sswf::TagButton::SetState().
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) { ... }
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.
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.
ptr | The pointer to re-allocate | |
size | The size of the new buffer | |
info | Information about the buffer (a static const string) |
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.
ptr | The pointer of which the size is to be returned |
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.
s1 | The string to appear on the left | |
s2 | The string to appear on the right |
References MemAlloc(), and StrDup().
Referenced by sswf::TagMetadata::Save().
char * MemoryManager::StrDup | ( | const char * | str | ) |
This function is used to duplicate a memory which buffer will be held in the memory manager.
str | The string to duplicate |
References MemAlloc().
Referenced by sswf::TagImport::AddName(), sswf::ActionFunction::AddParameter(), sswf::ActionPushData::AddString(), sswf::ActionDictionary::AddString(), sswf::TagMetadata::Save(), sswf::TagMetadata::SetAuthor(), sswf::TagMetadata::SetCopyright(), sswf::TagFont::SetCopyright(), sswf::TagMetadata::SetDescription(), sswf::TagFont::SetDisplayName(), sswf::TagProtect::SetEncodedPassword(), sswf::TagMetadata::SetFilename(), sswf::TagImport::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::TagExport::SetObject(), 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::SetVariableName(), and StrCat().
Buffer* sswf::MemoryManager::f_head [private] |
Referenced by MemAlloc(), MemAttach(), MemoryManager(), and ~MemoryManager().