Core Module refactored.

This commit is contained in:
Martín Lucas Golini
2014-06-14 03:24:12 -03:00
parent 810b4568aa
commit e4d342d8d0
6 changed files with 1042 additions and 1042 deletions

View File

@@ -7,7 +7,7 @@
namespace EE {
template<typename T>
class eeAllocator {
class Allocator {
public:
typedef T value_type;
typedef T * pointer;
@@ -17,13 +17,13 @@ class eeAllocator {
typedef ptrdiff_t difference_type;
typedef size_t size_type;
eeAllocator() {
Allocator() {
}
eeAllocator( const eeAllocator& ) {
Allocator( const Allocator& ) {
}
virtual ~eeAllocator() {
virtual ~Allocator() {
}
T * allocate( size_t cnt, typename std::allocator<void>::const_pointer ptr = 0 ) {
@@ -59,18 +59,18 @@ class eeAllocator {
return &x;
}
eeAllocator<T>& operator=(const eeAllocator&) { return *this; }
Allocator<T>& operator=(const Allocator&) { return *this; }
template <class U>
struct rebind {
typedef eeAllocator<U> other;
typedef Allocator<U> other;
};
template <class U>
eeAllocator( const eeAllocator<U>& ) {}
Allocator( const Allocator<U>& ) {}
template <class U>
eeAllocator& operator=(const eeAllocator<U>&) { return *this; }
Allocator& operator=(const Allocator<U>&) { return *this; }
protected:
};

View File

@@ -10,9 +10,9 @@
namespace EE {
class EE_API cAllocatedPointer {
class EE_API AllocatedPointer {
public:
cAllocatedPointer( void * Data, const std::string& File, int Line, size_t Memory );
AllocatedPointer( void * Data, const std::string& File, int Line, size_t Memory );
std::string mFile;
int mLine;
@@ -20,14 +20,14 @@ class EE_API cAllocatedPointer {
void * mData;
};
typedef std::map<void*, cAllocatedPointer> tAllocatedPointerMap;
typedef tAllocatedPointerMap::iterator tAllocatedPointerMapIt;
typedef std::map<void*, AllocatedPointer> AllocatedPointerMap;
typedef AllocatedPointerMap::iterator AllocatedPointerMapIt;
class EE_API MemoryManager {
public:
static void * AddPointer( const cAllocatedPointer& aAllocatedPointer );
static void * AddPointer( const AllocatedPointer& aAllocatedPointer );
static void * AddPointerInPlace( void * Place, const cAllocatedPointer& aAllocatedPointer );
static void * AddPointerInPlace( void * Place, const AllocatedPointer& aAllocatedPointer );
static bool RemovePointer( void * Data );
@@ -59,21 +59,21 @@ class EE_API MemoryManager {
static size_t GetTotalMemoryUsage();
static const cAllocatedPointer& GetBiggestAllocation();
static const AllocatedPointer& GetBiggestAllocation();
};
#ifdef EE_MEMORY_MANAGER
#define eeNew( classType, constructor ) \
( classType *)EE::MemoryManager::AddPointer( EE::cAllocatedPointer( new classType constructor ,__FILE__,__LINE__, sizeof(classType) ) )
( classType *)EE::MemoryManager::AddPointer( EE::AllocatedPointer( new classType constructor ,__FILE__,__LINE__, sizeof(classType) ) )
#define eeNewInPlace( place, classType, constructor ) \
( classType *)EE::MemoryManager::AddPointerInPlace( place, EE::cAllocatedPointer( new place classType constructor ,__FILE__,__LINE__, sizeof(classType) ) )
( classType *)EE::MemoryManager::AddPointerInPlace( place, EE::AllocatedPointer( new place classType constructor ,__FILE__,__LINE__, sizeof(classType) ) )
#define eeNewArray( classType, amount ) \
( classType *) EE::MemoryManager::AddPointer( EE::cAllocatedPointer( new classType [ amount ], __FILE__, __LINE__, amount * sizeof( classType ) ) )
( classType *) EE::MemoryManager::AddPointer( EE::AllocatedPointer( new classType [ amount ], __FILE__, __LINE__, amount * sizeof( classType ) ) )
#define eeMalloc(amount) \
EE::MemoryManager::AddPointer( EE::cAllocatedPointer( EE::MemoryManager::Allocate( amount ), __FILE__, __LINE__, amount ) )
EE::MemoryManager::AddPointer( EE::AllocatedPointer( EE::MemoryManager::Allocate( amount ), __FILE__, __LINE__, amount ) )
#define eeDelete( data ){ \
if( EE::MemoryManager::RemovePointer( EE::MemoryManager::Delete( data ) ) == false ) printf( "Deleting at '%s' %d\n", __FILE__, __LINE__ ); \

View File

@@ -8,7 +8,7 @@
namespace EE {
template <typename T, typename A = eeAllocator<T> >
struct eeStack {
struct Stack {
#ifdef EE_MEMORY_MANAGER
typedef typename std::stack<T, A> type;
#else
@@ -17,7 +17,7 @@ namespace EE {
};
template <typename T, typename A = eeAllocator<T> >
struct eeDeque {
struct Deque {
#ifdef EE_MEMORY_MANAGER
typedef typename std::deque<T, A> type;
#else
@@ -26,7 +26,7 @@ namespace EE {
};
template <typename T, typename A = eeAllocator<T> >
struct eeVector {
struct Vector {
#ifdef EE_MEMORY_MANAGER
typedef typename std::vector<T, A> type;
#else
@@ -35,7 +35,7 @@ namespace EE {
};
template <typename T, typename A = eeAllocator<T> >
struct eeList {
struct List {
#ifdef EE_MEMORY_MANAGER
typedef typename std::list<T, A> type;
#else
@@ -44,7 +44,7 @@ namespace EE {
};
template <typename T, typename P = std::less<T>, typename A = eeAllocator<T> >
struct eeSet {
struct Set {
#ifdef EE_MEMORY_MANAGER
typedef typename std::set<T, P, A> type;
#else
@@ -53,7 +53,7 @@ namespace EE {
};
template <typename K, typename V, typename P = std::less<K>, typename A = eeAllocator< std::pair<const K, V> > >
struct eeMap {
struct Map {
#ifdef EE_MEMORY_MANAGER
typedef typename std::map<K, V, P, A> type;
#else
@@ -62,7 +62,7 @@ namespace EE {
};
template <typename K, typename V, typename P = std::less<K>, typename A = eeAllocator< std::pair<const K, V> > >
struct eeMultimap {
struct Multimap {
#ifdef EE_MEMORY_MANAGER
typedef typename std::multimap<K, V, P, A> type;
#else

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -11,21 +11,21 @@ using namespace EE::System;
namespace EE {
static tAllocatedPointerMap sMapPointers;
static AllocatedPointerMap sMapPointers;
static size_t sTotalMemoryUsage = 0;
static size_t sPeakMemoryUsage = 0;
static cAllocatedPointer sBiggestAllocation = cAllocatedPointer( NULL, "", 0, 0 );
static AllocatedPointer sBiggestAllocation = AllocatedPointer( NULL, "", 0, 0 );
static cMutex sAllocMutex;
cAllocatedPointer::cAllocatedPointer( void * Data, const std::string& File, int Line, size_t Memory ) {
AllocatedPointer::AllocatedPointer( void * Data, const std::string& File, int Line, size_t Memory ) {
mData = Data;
mFile = File;
mLine = Line;
mMemory = Memory;
}
void * MemoryManager::AddPointerInPlace( void * Place, const cAllocatedPointer& aAllocatedPointer ) {
tAllocatedPointerMapIt it = sMapPointers.find( Place );
void * MemoryManager::AddPointerInPlace( void * Place, const AllocatedPointer& aAllocatedPointer ) {
AllocatedPointerMapIt it = sMapPointers.find( Place );
if ( it != sMapPointers.end() ) {
RemovePointer( Place );
@@ -34,10 +34,10 @@ void * MemoryManager::AddPointerInPlace( void * Place, const cAllocatedPointer&
return AddPointer( aAllocatedPointer );
}
void * MemoryManager::AddPointer( const cAllocatedPointer& aAllocatedPointer ) {
void * MemoryManager::AddPointer( const AllocatedPointer& aAllocatedPointer ) {
cLock l( sAllocMutex );
sMapPointers.insert( tAllocatedPointerMap::value_type( aAllocatedPointer.mData, aAllocatedPointer ) );
sMapPointers.insert( AllocatedPointerMap::value_type( aAllocatedPointer.mData, aAllocatedPointer ) );
sTotalMemoryUsage += aAllocatedPointer.mMemory;
@@ -55,7 +55,7 @@ void * MemoryManager::AddPointer( const cAllocatedPointer& aAllocatedPointer ) {
bool MemoryManager::RemovePointer( void * Data ) {
cLock l( sAllocMutex );
tAllocatedPointerMapIt it = sMapPointers.find( Data );
AllocatedPointerMapIt it = sMapPointers.find( Data );
if ( it == sMapPointers.end() ) {
eePRINTL( "Trying to delete pointer %p created that does not exist!", Data );
@@ -78,7 +78,7 @@ size_t MemoryManager::GetTotalMemoryUsage() {
return sTotalMemoryUsage;
}
const cAllocatedPointer& MemoryManager::GetBiggestAllocation() {
const AllocatedPointer& MemoryManager::GetBiggestAllocation() {
return sBiggestAllocation;
}
@@ -102,10 +102,10 @@ void MemoryManager::ShowResults() {
//Get max length of file name
int lMax =0;
tAllocatedPointerMapIt it = sMapPointers.begin();
AllocatedPointerMapIt it = sMapPointers.begin();
for( ; it != sMapPointers.end(); ++it ){
cAllocatedPointer &ap = it->second;
AllocatedPointer &ap = it->second;
if( (int)ap.mFile.length() > lMax )
lMax = (int)ap.mFile.length();
@@ -123,7 +123,7 @@ void MemoryManager::ShowResults() {
it = sMapPointers.begin();
for( ; it != sMapPointers.end(); ++it ) {
cAllocatedPointer &ap = it->second;
AllocatedPointer &ap = it->second;
eePRINT( "| %p\t %s", ap.mData, ap.mFile.c_str() );