1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: ut_FrameHeap.h 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Revision:$ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NW_UT_FRAME_HEAP_H_ 17 #define NW_UT_FRAME_HEAP_H_ 18 19 #include <nw/ut/ut_HeapBase.h> 20 21 namespace nw { 22 namespace ut { 23 24 //! @details :private 25 class FrameHeap : public HeapBase 26 { 27 public: 28 static const int FREE_HEAD = (1 << 0); 29 static const int FREE_TAIL = (1 << 1); 30 static const int FREE_ALL = (FREE_HEAD | FREE_TAIL); 31 32 private: 33 struct HeapState 34 { 35 u32 tagName; // タグ名 36 void* headAllocator; // フレームヒープの先頭位置 37 void* tailAllocator; // フレームヒープの末尾位置 38 HeapState* pPrevState; // 1 つ前の状態保存へのポインタ 39 HeapStateHeapState40 HeapState() : 41 tagName( 0 ), 42 headAllocator( NULL ), 43 tailAllocator( NULL ), 44 pPrevState( NULL ) 45 { 46 } 47 }; 48 49 public: 50 static FrameHeap* Create( void* startAddress, u32 heapSize, u16 optFlag = 0 ); 51 52 void* Destroy(); 53 void* Alloc( u32 size, int alignment = DEFAULT_ALIGNMENT ); 54 u32 ResizeForMBlock( void* memBlock, u32 newSize ); 55 u32 GetAllocatableSize( int alignment = DEFAULT_ALIGNMENT ); 56 void Free( int mode ); 57 bool RecordState( u32 tagName ); 58 bool FreeByState( u32 tagName ); 59 u32 Adjust(); 60 61 private: IsValid()62 bool IsValid() { return GetSignature() == FRMHEAP_SIGNATURE; } 63 64 void* AllocFromHead( u32 size, int alignment ); 65 void* AllocFromTail( u32 size, int alignment ); 66 67 void FreeHead(); 68 void FreeTail(); 69 70 void* mHeadAllocator; 71 void* mTailAllocator; 72 HeapState* mpState; 73 }; 74 75 76 } // nw::ut 77 } // nw 78 79 #endif // NW_UT_FRAME_HEAP_H_ 80