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