Added the memory manager class
This commit is contained in:
parent
4cff1194d0
commit
bea4b72893
|
@ -0,0 +1,165 @@
|
|||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// _
|
||||
// | |
|
||||
// _ __ ___ _ __ ___ __ _ _ __ | |__
|
||||
// | '_ ` _ \| '_ ` _ \ / _` | '__| | '_ \
|
||||
// | | | | | | | | | | | (_| | | _ | | | |
|
||||
// |_| |_| |_|_| |_| |_|\__, |_| (_)|_| |_|
|
||||
// __/ |
|
||||
// |___/
|
||||
//
|
||||
// Memory manager & tracking software
|
||||
//
|
||||
// Best viewed with 8-character tabs and (at least) 132 columns
|
||||
//
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Restrictions & freedoms pertaining to usage and redistribution of this software:
|
||||
//
|
||||
// * This software is 100% free
|
||||
// * If you use this software (in part or in whole) you must credit the author.
|
||||
// * This software may not be re-distributed (in part or in whole) in a modified
|
||||
// form without clear documentation on how to obtain a copy of the original work.
|
||||
// * You may not use this software to directly or indirectly cause harm to others.
|
||||
// * This software is provided as-is and without warrantee. Use at your own risk.
|
||||
//
|
||||
// For more information, visit HTTP://www.FluidStudios.com
|
||||
//
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// Originally created on 12/22/2000 by Paul Nettle
|
||||
//
|
||||
// Copyright 2000, Fluid Studios, Inc., all rights reserved.
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _H_MMGR
|
||||
#define _H_MMGR
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// For systems that don't have the __FUNCTION__ variable, we can just define it here
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#define __FUNCTION__ "??"
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// Types
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
typedef struct tag_au
|
||||
{
|
||||
size_t actualSize;
|
||||
size_t reportedSize;
|
||||
void *actualAddress;
|
||||
void *reportedAddress;
|
||||
char sourceFile[40];
|
||||
char sourceFunc[40];
|
||||
unsigned int sourceLine;
|
||||
unsigned int allocationType;
|
||||
bool breakOnDealloc;
|
||||
bool breakOnRealloc;
|
||||
unsigned int allocationNumber;
|
||||
struct tag_au *next;
|
||||
struct tag_au *prev;
|
||||
} sAllocUnit;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int totalReportedMemory;
|
||||
unsigned int totalActualMemory;
|
||||
unsigned int peakReportedMemory;
|
||||
unsigned int peakActualMemory;
|
||||
unsigned int accumulatedReportedMemory;
|
||||
unsigned int accumulatedActualMemory;
|
||||
unsigned int accumulatedAllocUnitCount;
|
||||
unsigned int totalAllocUnitCount;
|
||||
unsigned int peakAllocUnitCount;
|
||||
} sMStats;
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// External constants
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
extern const unsigned int m_alloc_unknown;
|
||||
extern const unsigned int m_alloc_new;
|
||||
extern const unsigned int m_alloc_new_array;
|
||||
extern const unsigned int m_alloc_malloc;
|
||||
extern const unsigned int m_alloc_calloc;
|
||||
extern const unsigned int m_alloc_realloc;
|
||||
extern const unsigned int m_alloc_delete;
|
||||
extern const unsigned int m_alloc_delete_array;
|
||||
extern const unsigned int m_alloc_free;
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// Used by the macros
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void m_setOwner(const char *file, const unsigned int line, const char *func);
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// Allocation breakpoints
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
bool &m_breakOnRealloc(void *reportedAddress);
|
||||
bool &m_breakOnDealloc(void *reportedAddress);
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// The meat of the memory tracking software
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void *m_allocator(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc,
|
||||
const unsigned int allocationType, const size_t reportedSize);
|
||||
void *m_reallocator(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc,
|
||||
const unsigned int reallocationType, const size_t reportedSize, void *reportedAddress);
|
||||
void m_deallocator(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc,
|
||||
const unsigned int deallocationType, const void *reportedAddress);
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// Utilitarian functions
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
bool m_validateAddress(const void *reportedAddress);
|
||||
bool m_validateAllocUnit(const sAllocUnit *allocUnit);
|
||||
bool m_validateAllAllocUnits();
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// Unused RAM calculations
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
unsigned int m_calcUnused(const sAllocUnit *allocUnit);
|
||||
unsigned int m_calcAllUnused();
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// Logging and reporting
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void m_dumpAllocUnit(const sAllocUnit *allocUnit, const char *prefix = "");
|
||||
void m_dumpMemoryReport(const char *filename = "memreport.log", const bool overwrite = true);
|
||||
sMStats m_getMemoryStatistics();
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// Variations of global operators new & delete
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void *operator new(size_t reportedSize);
|
||||
void *operator new[](size_t reportedSize);
|
||||
void *operator new(size_t reportedSize, const char *sourceFile, int sourceLine);
|
||||
void *operator new[](size_t reportedSize, const char *sourceFile, int sourceLine);
|
||||
void operator delete(void *reportedAddress);
|
||||
void operator delete[](void *reportedAddress);
|
||||
|
||||
#endif // _H_MMGR
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// Macros -- "Kids, please don't try this at home. We're trained professionals here." :)
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "cNonMemoryManager.h"
|
||||
#define new (m_setOwner (__FILE__,__LINE__,__FUNCTION__),false) ? NULL : new
|
||||
#define delete (m_setOwner (__FILE__,__LINE__,__FUNCTION__),false) ? m_setOwner("",0,"") : delete
|
||||
#define malloc(sz) m_allocator (__FILE__,__LINE__,__FUNCTION__,m_alloc_malloc,sz)
|
||||
#define calloc(sz) m_allocator (__FILE__,__LINE__,__FUNCTION__,m_alloc_calloc,sz)
|
||||
#define realloc(ptr,sz) m_reallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_realloc,sz,ptr)
|
||||
#define free(ptr) m_deallocator(__FILE__,__LINE__,__FUNCTION__,m_alloc_free,ptr)
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// mmgr.h - End of file
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
@ -0,0 +1,60 @@
|
|||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// _
|
||||
// | |
|
||||
// _ __ ___ _ __ ___ _ __ ___ __ _ _ __ | |__
|
||||
// | '_ \ / _ \| '_ ` _ \| '_ ` _ \ / _` | '__| | '_ \
|
||||
// | | | | (_) | | | | | | | | | | | (_| | | _ | | | |
|
||||
// |_| |_|\___/|_| |_| |_|_| |_| |_|\__, |_| (_)|_| |_|
|
||||
// __/ |
|
||||
// |___/
|
||||
//
|
||||
// Memory manager & tracking software
|
||||
//
|
||||
// Best viewed with 8-character tabs and (at least) 132 columns
|
||||
//
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Restrictions & freedoms pertaining to usage and redistribution of this software:
|
||||
//
|
||||
// * This software is 100% free
|
||||
// * If you use this software (in part or in whole) you must credit the author.
|
||||
// * This software may not be re-distributed (in part or in whole) in a modified
|
||||
// form without clear documentation on how to obtain a copy of the original work.
|
||||
// * You may not use this software to directly or indirectly cause harm to others.
|
||||
// * This software is provided as-is and without warrantee. Use at your own risk.
|
||||
//
|
||||
// For more information, visit HTTP://www.FluidStudios.com
|
||||
//
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// Originally created on 12/22/2000 by Paul Nettle
|
||||
//
|
||||
// Copyright 2000, Fluid Studios, Inc., all rights reserved.
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#ifdef new
|
||||
#undef new
|
||||
#endif
|
||||
|
||||
#ifdef delete
|
||||
#undef delete
|
||||
#endif
|
||||
|
||||
#ifdef malloc
|
||||
#undef malloc
|
||||
#endif
|
||||
|
||||
#ifdef calloc
|
||||
#undef calloc
|
||||
#endif
|
||||
|
||||
#ifdef realloc
|
||||
#undef realloc
|
||||
#endif
|
||||
|
||||
#ifdef free
|
||||
#undef free
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
// nommgr.h - End of file
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
@ -7,7 +7,7 @@ DEPEND=-logg -lopenal -lvorbis -lvorbisenc -lvorbisfile -ldl\
|
|||
|
||||
STATICDEPEND=/usr/lib/libogg.a /usr/lib/libopenal.so /usr/lib/libvorbis.a /usr/lib/libvorbisenc.a /usr/lib/libvorbisfile.a /usr/lib/libdl.a
|
||||
|
||||
OBJECT= cAudioCapture.o cAudioEffects.o cAudioManager.o cAudioSleep.o cAudioSource.o cConsoleLogReceiver.o cEffect.o cFileSource.o cFilter.o cFileLogReceiver.o cListener.o cLogger.o cMemorySource.o cMutex.o cOggAudioDecoderFactory.o cOggDecoder.o cPluginManager.o cRawDecoder.o cThread.o cWavAudioDecoderFactory.o cWavDecoder.o
|
||||
OBJECT= cAudioCapture.o cAudioEffects.o cAudioManager.o cAudioSleep.o cAudioSource.o cConsoleLogReceiver.o cEffect.o cFileSource.o cFilter.o cFileLogReceiver.o cListener.o cLogger.o cMemorySource.o cMutex.o cOggAudioDecoderFactory.o cOggDecoder.o cPluginManager.o cRawDecoder.o cThread.o cWavAudioDecoderFactory.o cWavDecoder.o cMemoryManager.o
|
||||
|
||||
LINK_OPTIONS=-shared
|
||||
COMPILE_OPTIONS=-fPIC
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,10 +2,15 @@
|
|||
// This file is part of the "cAudio Engine"
|
||||
// For conditions of distribution and use, see copyright notice in cAudio.h
|
||||
|
||||
#include "../Headers/cMemorySource.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef CAUDIO_USE_MMGR
|
||||
#include "../Headers/cMemorymanager.h"
|
||||
#endif
|
||||
|
||||
#include "../Headers/cMemorySource.h"
|
||||
|
||||
namespace cAudio
|
||||
{
|
||||
|
||||
|
|
|
@ -129,8 +129,10 @@
|
|||
<Unit filename="Headers\cFilter.h" />
|
||||
<Unit filename="Headers\cListener.h" />
|
||||
<Unit filename="Headers\cLogger.h" />
|
||||
<Unit filename="Headers\cMemoryManager.h" />
|
||||
<Unit filename="Headers\cMemorySource.h" />
|
||||
<Unit filename="Headers\cMutex.h" />
|
||||
<Unit filename="Headers\cNonMemoryManager.h" />
|
||||
<Unit filename="Headers\cOggAudioDecoderFactory.h" />
|
||||
<Unit filename="Headers\cOggDecoder.h" />
|
||||
<Unit filename="Headers\cPluginManager.h" />
|
||||
|
@ -152,6 +154,7 @@
|
|||
<Unit filename="Source\cFilter.cpp" />
|
||||
<Unit filename="Source\cListener.cpp" />
|
||||
<Unit filename="Source\cLogger.cpp" />
|
||||
<Unit filename="Source\cMemoryManager.cpp" />
|
||||
<Unit filename="Source\cMemorySource.cpp" />
|
||||
<Unit filename="Source\cMutex.cpp" />
|
||||
<Unit filename="Source\cOggAudioDecoderFactory.cpp" />
|
||||
|
|
|
@ -232,6 +232,10 @@
|
|||
RelativePath=".\Headers\cLogger.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Headers\cMemoryManager.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Headers\cMemorySource.h"
|
||||
>
|
||||
|
@ -240,6 +244,10 @@
|
|||
RelativePath=".\Headers\cMutex.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Headers\cNonMemoryManager.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Headers\cOggAudioDecoderFactory.h"
|
||||
>
|
||||
|
@ -332,6 +340,10 @@
|
|||
RelativePath=".\Source\cLogger.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Source\cMemoryManager.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Source\cMemorySource.cpp"
|
||||
>
|
||||
|
|
|
@ -62,4 +62,7 @@
|
|||
|
||||
#endif
|
||||
|
||||
//! Memory Managment Comment out to use the memory manager
|
||||
//#define CAUDO_USE_MMGR
|
||||
|
||||
#endif //! CAUDIODEFINES_H
|
||||
|
|
Loading…
Reference in New Issue