/*! @file sysHeap.h @brief ヒープ */ #ifndef SYS_HEAP_H_ #define SYS_HEAP_H_ #include #include #include //#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 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