#if !defined(__MEMORYMONITOR_IPP__)
#define __MEMORYMONITOR_IPP__
#include "MemoryMonitor.hpp"
#include "defines.h"
#include "new-operator.hpp"
#include "Debug.hpp"
INLINE int MemoryMonitor::init()
{
if( !wasInitialised )
{
statBufferSize = 8192;
hogSize = 8192;
if( hogSize != 0 )
{
memoryHog = new char[ hogSize ];
}
if( statBufferSize != 0 )
{
statBuffer = new StatRecord[ statBufferSize + 1 ];
}
wasInitialised = true;
}
return 0;
}
INLINE void MemoryMonitor::release()
{
if( memoryHog != NIL )
{
delete []memoryHog;
memoryHog = NIL;
}
}
INLINE void MemoryMonitor::inc( Index anAmount, void * )
{
allocated += anAmount;
if( anAmount > maxArea )
{
maxArea = anAmount;
}
if( wasInitialised && ( anAmount <= statBufferSize ) )
{
Index totalTimes;
totalTimes = ++( statBuffer[ anAmount ].total );
++( statBuffer[ anAmount ].actual );
statBuffer[ anAmount ].average =
( statBuffer[ anAmount ].average * ( totalTimes - 1 ) + statBuffer[ anAmount ].actual ) / totalTimes;
if( statBuffer[ anAmount ].actual > statBuffer[ anAmount ].max )
{
statBuffer[ anAmount ].max = statBuffer[ anAmount ].actual;
}
}
}
INLINE void MemoryMonitor::dec( Index anAmount, void * )
{
allocated -= anAmount;
testF_( amount >= 0 );
if( wasInitialised && ( anAmount <= statBufferSize ) )
{
Index totalTimes;
totalTimes = ++( statBuffer[ anAmount ].total );
--( statBuffer[ anAmount ].actual );
statBuffer[ anAmount ].average =
( statBuffer[ anAmount ].average * ( totalTimes - 1 ) +
statBuffer[ anAmount ].actual ) / totalTimes;
}
}
INLINE Index MemoryMonitor::amount()
{
return allocated;
}
INLINE boolean MemoryMonitor::checkDelete( const void *aPointer )
{
return checkForDelete( aPointer );
}
INLINE void MemoryMonitor::dumpStatistics()
{
Debug::getLogger() -> log( "Maximum area allocated: %li bytes", maxArea );
if( wasInitialised )
{
for( Index i = 0 ; i <= statBufferSize ; ++i )
{
if( statBuffer[ i ].total != 0 )
{
Debug::getLogger() ->
log( "%li: total: %li, actual: %li, average: %f, max: %li",
i,
statBuffer[ i ].total,
statBuffer[ i ].actual,
statBuffer[ i ].average,
statBuffer[ i ].max );
}
}
}
}
#endif