JD2022-TU1/main/extern/Raki/Source/RakiTests/System/SystemAllocator.h

97 lines
2.1 KiB
C++

#ifndef RAKI_SYSTEMALLOCATOR_H
#define RAKI_SYSTEMALLOCATOR_H
#include "RakiEngine/System/Memory/Allocator.h"
#if defined ( RAKI_TARGET_DEBUG ) && !defined ( RAKI_PLATFORM_WII ) && !defined ( RAKI_PLATFORM_CAFE )
#define RAKI_SYSTEMMEMORY_CHECKFORLEAKS
#endif // defined ( RAKI_TARGET_DEBUG ) && !defined ( RAKI_PLATFORM_WII ) && !defined ( RAKI_PLATFORM_CAFE )
#if defined ( RAKI_SYSTEMMEMORY_CHECKFORLEAKS )
#include <map>
#endif // defined ( RAKI_SYSTEMMEMORY_CHECKFORLEAKS )
// this is the default system allocator, which uses malloc and free and which SHOULD NOT BE USED other than in tests
// use the game's allocator instead
namespace raki
{
void SystemAllocator_Initialize();
class SystemAllocator
: public Allocator
{
public:
SystemAllocator();
virtual ~SystemAllocator();
virtual void * malloc( const u64 _size, const Memory::Type _type );
virtual void free( void * _ptr );
virtual void * mallocAligned( const u64 _size, const u64 _alignment, const Memory::Type _type );
virtual void freeAligned( void * _ptr );
#if defined ( RAKI_PLATFORM_WII )
virtual void * mallocMem2Aligned32( const u64 _size, const Memory::Type _type );
virtual void freeMem2Aligned32( void * _ptr );
#elif defined ( RAKI_PLATFORM_CAFE )
virtual void * mallocAligned64( const u64 _size, const Memory::Type _type );
virtual void freeAligned64( void * _ptr );
#elif defined ( RAKI_PLATFORM_XB360 ) || defined ( RAKI_PLATFORM_SCARLETT )
virtual void * mallocPhysicalAligned( const u64 _size, const Memory::Type _type );
virtual void freePhysicalAligned( void * _ptr );
#endif
virtual u64 getUsedSize();
virtual void memcpy( void * _dest, const void * _src, const u64 _size );
virtual void memZero( void * _dest, const u64 _size );
virtual i64 memcmp( const void * _ptrA, const void * _ptrB, const u64 _size );
private:
#if defined ( RAKI_SYSTEMMEMORY_CHECKFORLEAKS )
typedef std::map< u64, u64 > MemoryContainer;
MemoryContainer m_allocated;
MemoryContainer m_allocatedAligned;
#endif // defined ( RAKI_SYSTEMMEMORY_CHECKFORLEAKS )
};
}
#endif // RAKI_SYSTEMALLOCATOR_H