ctr_Repair/trunk/SkipFirstLaunch/sysHeap.h
N2614 57bec8362f MSETのヒープ管理ライブラリを使うように
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@665 385bec56-5757-e545-9c3a-d8741f4650f1
2012-03-15 06:26:23 +00:00

170 lines
3.5 KiB
C++

/*!
@file sysHeap.h
@brief ヒープ
*/
#ifndef SYS_HEAP_H_
#define SYS_HEAP_H_
#include <nw/types.h>
#include <nn/fnd.h>
#include <nw.h>
//#include "sysMacro.h"
namespace sys
{
#ifndef NW_RELEASE
class SceneMem
{
public:
SceneMem( void* address, int id, u32 size ) :
mpAddress( address ),
mID( id ),
mSize( size ){}
void* getAddress(){ return mpAddress; }
int getID(){ return mID; }
u32 getSize(){ return mSize; }
nw::ut::LinkListNode mLink;
private:
void* mpAddress;
int mID;
u32 mSize;
};
#endif
class Heap
{
public:
nn::fnd::ThreadSafeExpHeap* getHeap()
{
return &msHeap;
}
private:
nn::fnd::ThreadSafeExpHeap msHeap;
};
class Allocator;
class Mem
{
public:
static void init();
static void finish();
static void* AllocDeviceMemory( size_t size, s32 alignment );
static void* Alloc( Heap* p_heap, size_t size, s32 alignment );
static void Free( void* memory );
static Heap* getMainHeap(){ return &smMainHeap; }
static Heap* getSceneHeap(){ return &smSceneHeap; }
static Heap* getDeviceHeap(){ return &smDeviceHeap; }
#ifndef NW_RELEASE
static bool checkSceneHeap( int scene_id );
static size_t getMainFreeSize()
{
return smMainHeap.getHeap()->GetTotalFreeSize();
}
static size_t getSceneFreeSize()
{
return smSceneHeap.getHeap()->GetTotalFreeSize();
}
static size_t getDeviceFreeSize()
{
return smDeviceHeap.getHeap()->GetTotalFreeSize();
}
#endif
private:
#ifndef NW_RELEASE
typedef nw::ut::LinkList<SceneMem, offsetof( SceneMem, mLink )> MemList;
static MemList smList;
#endif
static Heap smMainHeap;
static Heap smSceneHeap;
static Heap smDeviceHeap;
};
/*!
SDKメモリアロケータ
*/
class SdkAllocator : public nn::fnd::IAllocator
{
public:
virtual void* Allocate( size_t size, s32 alignment )
{
return sys::Mem::Alloc( NULL, size, alignment );
}
virtual void Free(void* memory)
{
sys::Mem::Free( memory );
}
};
/*!
メモリアロケータ
*/
class Allocator : public nw::os::IAllocator
{
public:
virtual void* Alloc( size_t size, u8 alignment )
{
return sys::Mem::Alloc( NULL, size, alignment );
}
using nw::os::IAllocator::Alloc;
virtual void Free(void* memory)
{
sys::Mem::Free( memory );
}
};
/*!
デバイスメモリアロケータ
*/
class DeviceAllocator : public nw::os::IAllocator
{
public:
virtual void* Alloc( size_t size, u8 alignment )
{
return sys::Mem::AllocDeviceMemory( size, alignment );
}
using nw::os::IAllocator::Alloc;
virtual void Free( void* memory )
{
sys::Mem::Free( memory );
}
};
}
extern void* operator new( size_t size, sys::Heap* p_heap, int alignment = NN_FND_HEAP_DEFAULT_ALIGNMENT ) throw();
extern void* operator new( size_t size, int alignment = NN_FND_HEAP_DEFAULT_ALIGNMENT ) throw();
extern void* operator new[]( size_t size, const ::std::nothrow_t& ) throw();
extern void* operator new[]( size_t size, sys::Heap* p_heap, int alignment = NN_FND_HEAP_DEFAULT_ALIGNMENT ) throw();
extern void* operator new[]( size_t size, int alignment = NN_FND_HEAP_DEFAULT_ALIGNMENT ) throw();
extern void operator delete( void* mem_block ) throw();
extern void operator delete[]( void* mem_block ) throw();
#endif