OROCHI
 
Loading...
Searching...
No Matches
GxAllocatorDefault.h
Go to the documentation of this file.
1//===========================================================================
10//===========================================================================
11#pragma once
12
13GX_CORE_NAMESPACE_BEGIN()
14
15//===========================================================================
17//===========================================================================
19{
20 //-----------------------------------------------------------
22 //-----------------------------------------------------------
24public:
25 // RTTI定義
26 GX_RTTI_STRUCT(GxAllocatorDefault)
27 // ClassBase継承クラス用禁止宣言
29
30private:
32 struct GxAllocateInformation
33 {
34 void* _pAddress;
35 u32 _size;
36 GX_CSTR _filename;
37 u32 _line;
38 };
39
41 //-----------------------------------------------------------
43 //-----------------------------------------------------------
45
46private:
52 void initialize(void** pBuffer, u32& size);
53
55 //-----------------------------------------------------------
57 //-----------------------------------------------------------
59
60public:
61#if GX_DEBUG_NEW
63 void* allocateMemory(u32 size, GX_CSTR filename, u32 line, GxMemory::ALIGNMENT alignment = GxMemory::ALIGNMENT::_16);
65 void freeMemory(void* pAddress, GX_CSTR filename, u32 line);
66#else // GX_DEBUG_NEW
68 void* allocateMemory(u32 size, GxMemory::ALIGNMENT alignment = GxMemory::ALIGNMENT::_16);
70 void freeMemory(void* pAddress);
71#endif // !GX_DEBUG_NEW
72
73#if GX_DEVELOP
75 void checkMemoryLeak(void) const;
76#endif // GX_DEVELOP
77
78private:
80 GxAllocateInformation* findAllocateInformation(void* pAddress) const;
81
83 //-----------------------------------------------------------
85 //-----------------------------------------------------------
87public:
89 static GxAllocatorDefault& getInstance(void){ static GxAllocatorDefault instance; return instance; }
91 constexpr u32 getSize(void) const { return _allocateSize; }
93 b32 isValidAddress(void* pAddress) const;
94
96 //-----------------------------------------------------------
98 //-----------------------------------------------------------
100private:
101 void* _pBuffer;
102 u32 _bufferSize;
103 void* _pTail;
104 GxAllocateInformation* _pAllocateInformation;
105 u32 _allocateSize;
106#if GX_DEVELOP
107 s32 _allocateCount;
108 u32 _remainSize;
109 u32 _remainMinSize;
110#endif // GX_DEVELOP
111
113};
114
115//-----------------------------------------------------------
116// GxAllocatorDefault のサイズ指定マクロ
117//-----------------------------------------------------------
118#define GX_ALLOCATOR_DEFAULT_SIZE(__size) \
119 void GxAllocatorDefault::initialize(void** ppBuffer, u32& size) \
120 { \
121 const u32 bufferSize = __size; \
122 static u8 buffer[bufferSize]; \
123 size = bufferSize; \
124 *ppBuffer = static_cast<void*>(buffer); \
125 }
126
127//-----------------------------------------------------------
128// アクセスインターフェース
129//-----------------------------------------------------------
131
132GX_CORE_NAMESPACE_END()
#define GX_PROHIBIT_CLASS_BASE(__CLASS__)
GxClassBase継承の禁止宣言
Definition GxBase.h:240
ディフォルトアロケータクラス
Definition GxAllocatorDefault.h:19
constexpr u32 getSize(void) const
確保サイズ取得
Definition GxAllocatorDefault.h:91
static GxAllocatorDefault & getInstance(void)
インスタンス取得
Definition GxAllocatorDefault.h:89
オブジェクト基底クラス
Definition GxBase.h:88
ALIGNMENT
メモリアライメント定義
Definition GxMemory.h:51
@ _16
16byteアライメント
Definition GxMemory.h:54
32bitブーリアン
Definition GxDefine.h:173