OROCHI
 
Loading...
Searching...
No Matches
GxAllocator.h
Go to the documentation of this file.
1//===========================================================================
10//===========================================================================
11#pragma once
12
13//---------------------------------------------------------------------------
15//---------------------------------------------------------------------------
17#if GX_DEBUG_NEW
18
19// 通常 (GxClassBaseReference継承は配列new, delete禁止なのでこちら)
20// param allocatorNumber [in] 使用アロケータ番号
21#define GX_OPERATOR_NEW_DELETE(allcatorNumber) \
22 void* operator new (size_t size, GX_CSTR filename = __FILE__, u32 line = __LINE__) { return gx::core::GxAllocatorList::getAllocator(allcatorNumber)->allocateMemory(gx::core::GxAllocatorList::getType(allcatorNumber), static_cast<u32>(size), filename, line); } \
23 void operator delete (void* pAddress, GX_CSTR filename, u32 line) { gx::core::GxAllocatorList::getAllocator(allcatorNumber)->freeMemory(pAddress, filename, line); } \
24 void operator delete (void* pAddress) { gx::core::GxAllocatorList::getAllocator(allcatorNumber)->freeMemory(pAddress, __FILE__, __LINE__); } \
25 void* operator new (size_t, void* where) { return (where); } \
26 void operator delete (void*, void*) {} \
27/*private:*/ \
28 GX_DEPRECATED_BEGIN void* operator new[] (size_t size, GX_CSTR filename = __FILE__, u32 line = __LINE__) GX_DEPRECATED_END { return gx::core::GxAllocatorList::getAllocator(allcatorNumber)->allocateMemory(gx::core::GxAllocatorList::getType(allcatorNumber), static_cast<u32>(size), filename, line); } \
29 GX_DEPRECATED_BEGIN void operator delete[] (void* pAddress, GX_CSTR filename, u32 line) GX_DEPRECATED_END { gx::core::GxAllocatorList::getAllocator(allcatorNumber)->freeMemory(pAddress, filename, line); } \
30 GX_DEPRECATED_BEGIN void operator delete[] (void* pAddress) GX_DEPRECATED_END { gx::core::GxAllocatorList::getAllocator(allcatorNumber)->freeMemory(pAddress, __FILE__, __LINE__); } \
31public:
32
33
34// 配列new, delete有効Ver
35// param allocatorNumber [in] 使用アロケータ番号
36#define GX_OPERATOR_NEW_DELETE_USE_ARRAY(allcatorNumber) \
37 void* operator new (size_t size, GX_CSTR filename = __FILE__, u32 line = __LINE__) { return gx::core::GxAllocatorList::getAllocator(allcatorNumber)->allocateMemory(gx::core::GxAllocatorList::getType(allcatorNumber), static_cast<u32>(size), filename, line); } \
38 void* operator new[] (size_t size, GX_CSTR filename = __FILE__, u32 line = __LINE__) { return gx::core::GxAllocatorList::getAllocator(allcatorNumber)->allocateMemory(gx::core::GxAllocatorList::getType(allcatorNumber), static_cast<u32>(size), filename, line); } \
39 void operator delete (void* pAddress, GX_CSTR filename, u32 line) { gx::core::GxAllocatorList::getAllocator(allcatorNumber)->freeMemory(pAddress, filename, line); } \
40 void operator delete[] (void* pAddress, GX_CSTR filename, u32 line) { gx::core::GxAllocatorList::getAllocator(allcatorNumber)->freeMemory(pAddress, filename, line); } \
41 void operator delete (void* pAddress) { gx::core::GxAllocatorList::getAllocator(allcatorNumber)->freeMemory(pAddress, __FILE__, __LINE__); } \
42 void operator delete[] (void* pAddress) { gx::core::GxAllocatorList::getAllocator(allcatorNumber)->freeMemory(pAddress, __FILE__, __LINE__); } \
43 void* operator new (size_t, void* where) { return (where); } \
44 void operator delete (void*, void*) {}
45
46#else // GX_DEBUG_NEW
47
48// 通常 (GxClassBaseReference継承は配列new, delete禁止なのでこちら)
49#define GX_OPERATOR_NEW_DELETE(allcatorNumber) \
50 void* operator new (size_t size) { return gx::core::GxAllocatorList::getAllocator(allcatorNumber)->allocateMemory(gx::core::GxAllocatorList::getType(allcatorNumber), (u32)size); } \
51 void operator delete (void* pAddress) { gx::core::GxAllocatorList::getAllocator(allcatorNumber)->freeMemory(pAddress); } \
52 void* operator new (size_t, void* where) { return (where); } \
53 void operator delete (void*, void*) {} \
54/*private:*/ \
55 GX_DEPRECATED_BEGIN void* operator new[] (size_t size) GX_DEPRECATED_END { return gx::core::GxAllocatorList::getAllocator(allcatorNumber)->allocateMemory(gx::core::GxAllocatorList::getType(allcatorNumber), (u32)size); } \
56 GX_DEPRECATED_BEGIN void operator delete[] (void* pAddress) GX_DEPRECATED_END { gx::core::GxAllocatorList::getAllocator(allcatorNumber)->freeMemory(pAddress); } \
57public:
58
59// 配列new, delete有効Ver
60#define GX_OPERATOR_NEW_DELETE_USE_ARRAY(allcatorNumber) \
61 void* operator new (size_t size) { return gx::core::GxAllocatorList::getAllocator(allcatorNumber)->allocateMemory(gx::core::GxAllocatorList::getType(allcatorNumber), (u32)size); } \
62 void* operator new[] (size_t size) { return gx::core::GxAllocatorList::getAllocator(allcatorNumber)->allocateMemory(gx::core::GxAllocatorList::getType(allcatorNumber), (u32)size); } \
63 void operator delete (void* pAddress) { gx::core::GxAllocatorList::getAllocator(allcatorNumber)->freeMemory(pAddress); } \
64 void operator delete[] (void* pAddress) { gx::core::GxAllocatorList::getAllocator(allcatorNumber)->freeMemory(pAddress); } \
65 void* operator new (size_t, void* where) { return (where); } \
66 void operator delete (void*, void*) {}
67
68#endif // GX_DEBUG_NEW
69
71
72
73GX_CORE_NAMESPACE_BEGIN()
74
75//---- クラス宣言
77
78//===========================================================================
80//===========================================================================
82{
83 //-----------------------------------------------------------
85 //-----------------------------------------------------------
87public:
88 // RTTI宣言
89 GX_RTTI_CLASS(GxAllocator, GxClassBase)
90 // GxClassBase継承クラス用禁止宣言
92
93
95 {
96 ATTRIBUTE_ZERO_CLEAR = (1 << 0),
97 ATTRIBUTE_THREAD_SAFE = (1 << 1),
98 ATTRIBUTE_SEQUENTIAL_THREAD_SAFE = (1 << 2),
99 ATTRIBUTE_TRACE = (1 << 3),
100 ATTRIBUTE_LOCKED_TRACE = (1 << 4)
101 };
102
103 // 確保タイプ
104 static constexpr u32 ALLOCATE_TYPE_DEFAULT = 0;
105
106protected:
107#if GX_DEVELOP && defined(_DEBUG)
109 static constexpr u8 FILL_MAGIC_NUMBER = 0xcd;
110#endif //GX_DEVELOP && _DEBUG
111
113 //-----------------------------------------------------------
115 //-----------------------------------------------------------
117protected:
119 GxAllocator(void);
121 GxAllocator(GxMemory::TYPE type, GX_CSTR name);
122
123public:
125 ~GxAllocator(void) override;
126
128 //-----------------------------------------------------------
130 //-----------------------------------------------------------
132public:
133#if GX_DEBUG_NEW
135 virtual void* allocateMemory(u32 type, u32 size, GX_CSTR filename, u32 line, GxMemory::ALIGNMENT alignment = GxMemory::ALIGNMENT::_16);
137 virtual void freeMemory(void* pAddress, GX_CSTR filename, u32 line);
139 virtual void* reallocMemory(void* pAddress, u32 size, GX_CSTR filename, u32 line);
140#else // GX_DEBUG_NEW
142 virtual void* allocateMemory(u32 type, u32 size, GxMemory::ALIGNMENT alignment = GxMemory::ALIGNMENT::_16);
144 virtual void freeMemory(void* pAddress);
146 virtual void* reallocMemory(void* pAddress, u32 size);
147#endif // GX_DEBUG_NEW
148
150 virtual b32 isValidAddr(const void* pAddress);
151
152#if GX_DEVELOP
154 static GxGuiBase* createGui(GxProperty& property, GxTypedObject* pOwner, const GxRtti& rtti, u32 index);
155
157 virtual void printInformation(void);
158#endif // GX_DEVELOP
159
160protected:
162 void lock(void);
164 void unlock(void);
166 void initializeAllocateBuffer(void* pAddress, u32 size);
168 void terminateAllocateBuffer(void* pAddress, u32 size);
169
170#if GX_DEVELOP
171#if defined(_DEBUG)
173 b32 isValidAllocateBuffer(const void* pAddress, u32 size) const;
174#endif //_DEBUG
176 virtual void traceAllocateInformation(const void* pAddress, u32 size, GX_CSTR filename = nullptr, u32 line = 0) const;
178 virtual void traceFreeInformation(const void* pAddress, GX_CSTR filename = nullptr, u32 line = 0) const;
179#endif // GX_DEVELOP
180
182 //-----------------------------------------------------------
184 //-----------------------------------------------------------
186
187public:
189 constexpr void* getAddress(void) const { return _pAddress; }
191 constexpr u32 getSize(void) const { return _size; }
193 constexpr u32 getAttribute(void) const { return _attribute; }
195 constexpr void setAttribute(u32 attribute) { _attribute = attribute; }
197 constexpr void addAttribute(u32 attribute) { _attribute |= attribute; }
199 constexpr GxMemory::TYPE getMemoryType(void) const { return _type; }
200#if GX_DEVELOP
202 constexpr GX_CSTR getAllocatorName(void) const { return _name; }
204 constexpr void setAllocatorName(GX_CSTR name) { _name = name; }
206 void setColor(const GxColor& color) { _color = color; }
208 const GxColor& getColor(void) const { return _color; }
209#endif // GX_DEVELOP
210
212 //-----------------------------------------------------------
214 //-----------------------------------------------------------
216protected:
218 void* _pAddress;
219 u32 _size;
222#if GX_DEVELOP
223 GX_CSTR _name;
224 GxColor _color;
225#endif // GX_DEVELOP
226
228};
229
230//---------------------------------------------------------------------------
231// 確保メモリ初期化
234//---------------------------------------------------------------------------
235GX_FORCE_INLINE void GxAllocator::initializeAllocateBuffer(void* pAddress, u32 size)
236{
237 if( pAddress )
238 {
239 // ゼロクリア (属性有効時のみ)
241 {
242 GX_MEMSET(pAddress, 0, size);
243 }
244#if GX_DEVELOP && defined(_DEBUG)
245 // マジックナンバー埋め込み (開発時のみ)
246 else
247 {
248 GX_MEMSET(pAddress, FILL_MAGIC_NUMBER, size);
249 }
250#endif //GX_DEVELOP && _DEBUG
251 }
252}
253
254//---------------------------------------------------------------------------
255// 確保メモリ終了
258//---------------------------------------------------------------------------
259GX_FORCE_INLINE void GxAllocator::terminateAllocateBuffer(void* pAddress, u32 size)
260{
261#if GX_DEVELOP && defined(_DEBUG)
262 if(pAddress)
263 {
264 // マジックナンバー埋め込み (開発時のみ)
265 GX_MEMSET(pAddress, FILL_MAGIC_NUMBER, size);
266 }
267#else // GX_DEVELOP && _DEBUG
268 GX_UNUSED(pAddress);
269 GX_UNUSED(size);
270#endif // GX_DEVELOP && _DEBUG
271}
272
273#if GX_DEVELOP
274#if defined(_DEBUG)
275//---------------------------------------------------------------------------
276// 確保メモリ正常チェック
281//---------------------------------------------------------------------------
282GX_FORCE_INLINE b32 GxAllocator::isValidAllocateBuffer(const void* pAddress, u32 size) const
283{
284 b32 ret = true;
285
286 if(pAddress)
287 {
288 // マジックナンバーチェック
289 const auto* pPointer = reinterpret_cast<const u8*>(pAddress);
290 const auto check = FILL_MAGIC_NUMBER;
291 for( u32 i = 0; i < size; ++i, ++pPointer)
292 {
293 if( GX_MEMCMP(pPointer, &check, sizeof(u8)) )
294 {
295 GX_ASSERT(false, "isValidAllocateBuffer Error!! addr(0x%p) is not valid value(0x%x)", pPointer, *pPointer);
296 ret = false;
297 }
298 }
299 }
300
301 return ret;
302}
303#endif //_DEBUG
304
305//---------------------------------------------------------------------------
306// 確保メモリ情報出力
311//---------------------------------------------------------------------------
312GX_FORCE_INLINE void GxAllocator::traceAllocateInformation(const void* pAddress, u32 size, GX_CSTR filename, u32 line) const
313{
315 {
316 GX_TRACE(GX_TRACE_CATEGORY_CORE, "[allocate] addr=0x%p size=%d", pAddress, size);
317 if( filename )
318 {
319 GX_TRACE(GX_TRACE_CATEGORY_CORE, " %s (%d)", filename, line);
320 }
321 }
322}
323
324//---------------------------------------------------------------------------
325// 解放メモリ情報出力
329//---------------------------------------------------------------------------
330GX_FORCE_INLINE void GxAllocator::traceFreeInformation(const void* pAddress, GX_CSTR filename, u32 line) const
331{
333 {
334 GX_TRACE(GX_TRACE_CATEGORY_CORE, "[free] addr=0x%p", pAddress);
335 if( filename )
336 {
337 GX_TRACE(GX_TRACE_CATEGORY_CORE, " %s (%d)", filename, line);
338 }
339 }
340}
341#endif // GX_DEVELOP
342
343//===========================================================================
345//===========================================================================
347{
348 //-----------------------------------------------------------
350 //-----------------------------------------------------------
352public:
354 enum class ALLOCATOR_TYPE : u32
355 {
356 GLOBAL = 0,
357 UNIT,
358 EFFECT,
359 SOUND,
360 RESOURCE,
361 SYSTEM,
362 RENDER,
363 PHYSICS,
364 TEMPORARY,
365#if GX_DEVELOP
366 DEVELOP,
367#endif // GX_DEVELOP
368
369 SYSTEM_MAX,
371 MAX = 16,
372
373 INVALID = 0xFFFFFFFF
374 };
375
376#if GX_DEVELOP
378 static const GX_CHAR* SYSTEM_ALLOCATOR_NAMES[static_cast<u32>(ALLOCATOR_TYPE::SYSTEM_MAX)];
380 static const GxColor SYSTEM_ALLOCATOR_COLORS[static_cast<u32>(ALLOCATOR_TYPE::SYSTEM_MAX)];
381#endif //GX_DEVELOP
382
385 {
388 u64 _size;
391#if GX_DEVELOP
392 GX_CSTR _name;
393 GxColor _color;
394#endif // GX_DEVELOP
395 };
396
397 static constexpr u32 SIZE_REMAIN_ALL = U32_MAX;
398
399 // GxClassBase継承クラス用禁止宣言
401
402
403 //-----------------------------------------------------------
405 //-----------------------------------------------------------
407public:
409 GxAllocatorList(void);
413 static void initialize(const GxCreateInformation* pAllocatorInformation, u32 count);
415 static void terminate(void);
417 static b32 createAllocatorList(const GxCreateInformation* pAllocatorInformation, u32 count);
419 static void releaseAllocatorList(void);
420
422 //-----------------------------------------------------------
424 //-----------------------------------------------------------
426public:
430 static GxAllocatorList* getAllocatorList(const void* pAddress);
431
433 static void getAllAllocator(GxArrayClassBase& dst);
434
436 static GxAllocator* getAllocator(GxAllocatorList::ALLOCATOR_TYPE number){ return getAllocatorList(number)->_pAllocator; }
438 static GxAllocator* getAllocator(const void* pAddress) { auto* pAllocatorList = getAllocatorList(pAddress); return (pAllocatorList)? pAllocatorList->_pAllocator : nullptr; }
440 static u32 getType(GxAllocatorList::ALLOCATOR_TYPE number) { return getAllocatorList(number)->_type; }
442 static void setType(GxAllocatorList::ALLOCATOR_TYPE number, u32 type){ getAllocatorList(number)->_type = type; }
443
445 static u32 getCount(void) { return static_cast<s32>(ALLOCATOR_TYPE::SYSTEM_MAX) + _userAllocatorListCount; }
447 static u32 getUserListCount(void) { return _userAllocatorListCount; }
448
450 static u64 getAvailableMemoryBeforeCreateAllocator(void) { return _availableMemoryBeforeCreateAllocator; }
452 static u64 getAvailableMemoryAfterCreateAllocator(void) { return _availableMemoryAfterCreateAllocator; }
453
455 static u32 getHardwareReservedMemoryTotal(void);
457 static u32 getHardwareReservedMemoryUsed(void);
459 static u32 getHardwareReservedMemoryFree(void);
460
461public:
463 constexpr GxAllocator* getAllocator(void) const { return _pAllocator; }
465 constexpr u32 getType(void) const { return _type; }
466#if GX_DEVELOP
468 constexpr void setName(GX_CSTR name) { _name = name; }
470 constexpr GX_CSTR getName(void) const { return _name; }
471#endif // GX_DEVELOP
472
474 //-----------------------------------------------------------
476 //-----------------------------------------------------------
478public:
480 static void attach(GxAllocatorList::ALLOCATOR_TYPE number, GxAllocator* pAllocator, u32 type = 0);
484 static void detach(const GxAllocator* pAllocator);
486 static u64 getAllAllocatorMemorySize(void);
487
488#if GX_DEVELOP
490 static void printInformation(void);
491#endif // GX_DEVELOP
492
494 //-----------------------------------------------------------
496 //-----------------------------------------------------------
498
499private:
500 GxAllocator* _pAllocator;
501 u32 _type;
502#if GX_DEVELOP
503 GX_CSTR _name;
504#endif // GX_DEVELOP
505
506private:
507 static GxAllocatorList _systemAllocatorList[static_cast<s32>(ALLOCATOR_TYPE::SYSTEM_MAX)];
508 static GxAllocatorList* _pUserAllocatorList;
509 static u32 _userAllocatorListCount;
510 static u64 _availableMemoryBeforeCreateAllocator;
511 static u64 _availableMemoryAfterCreateAllocator;
512
514};
515
516//---------------------------------------------------------------------------
517// アロケータリストアクセスインターフェース
518//---------------------------------------------------------------------------
519GX_FORCE_INLINE GxAllocatorList* getGxAllocatorList(GxAllocatorList::ALLOCATOR_TYPE index){ return GxAllocatorList::getAllocatorList(index); }
520
521//---------------------------------------------------------------------------
522// メモリ確保、解放アクセスインターフェイス (※GX_DEBUG_NEWの吸収)
523//---------------------------------------------------------------------------
524
525//---- アロケータリスト指定
526
532#if GX_DEBUG_NEW
533#define GX_ALLOCATE_MEMORY(pAllocatorList, size) ((pAllocatorList)->getAllocator())->allocateMemory((pAllocatorList)->getType(), size, __FILE__, __LINE__)
534#define GX_ALLOCATE_MEMORY_NAME(pAllocatorList, size, name) ((pAllocatorList)->getAllocator())->allocateMemory((pAllocatorList)->getType(), size, __FILE__ "::" name, __LINE__)
535#else // GX_DEBUG_NEW
536#define GX_ALLOCATE_MEMORY(pAllocatorList, size) ((pAllocatorList)->getAllocator())->allocateMemory((pAllocatorList)->getType(), size)
537#define GX_ALLOCATE_MEMORY_NAME(pAllocatorList, size, name) ((pAllocatorList)->getAllocator())->allocateMemory((pAllocatorList)->getType(), size)
538#endif // GX_DEBUG_NEW
539
546#if GX_DEBUG_NEW
547#define GX_ALLOCATE_MEMORY_ALIGNMENT(pAllocatorList, size, alignment) ((pAllocatorList)->getAllocator())->allocateMemory((pAllocatorList)->getType(), size, __FILE__, __LINE__, alignment)
548#define GX_ALLOCATE_MEMORY_ALIGNMENT_NAME(pAllocatorList, size, alignment, name) ((pAllocatorList)->getAllocator())->allocateMemory((pAllocatorList)->getType(), size, __FILE__ "::" name, __LINE__, alignment)
549#else // GX_DEBUG_NEW
550#define GX_ALLOCATE_MEMORY_ALIGNMENT(pAllocatorList, size, alignment) ((pAllocatorList)->getAllocator())->allocateMemory((pAllocatorList)->getType(), size, alignment)
551#define GX_ALLOCATE_MEMORY_ALIGNMENT_NAME(pAllocatorList, size, alignment, name) ((pAllocatorList)->getAllocator())->allocateMemory((pAllocatorList)->getType(), size, alignment)
552#endif // GX_DEBUG_NEW
553
554//---- アロケータ + タイプ指定
555
562#if GX_DEBUG_NEW
563#define GX_ALLOCATE_MEMORY_TYPE(allocator, type, size) (allocator)->allocateMemory(type, size, __FILE__, __LINE__)
564#define GX_ALLOCATE_MEMORY_TYPE_NAME(allocator, type, size, name) (allocator)->allocateMemory(type, size, __FILE__ "::" name, __LINE__)
565#else // GX_DEBUG_NEW
566#define GX_ALLOCATE_MEMORY_TYPE(allocator, type, size) (allocator)->allocateMemory(type, size)
567#define GX_ALLOCATE_MEMORY_TYPE_NAME(allocator, type, size, name) (allocator)->allocateMemory(type, size)
568#endif // GX_DEBUG_NEW
569
577#if GX_DEBUG_NEW
578#define GX_ALLOCATE_MEMORY_TYPE_ALIGNMENT(allocator, type, size, alignment) (allocator)->allocateMemory(type, size, __FILE__, __LINE__, alignment)
579#define GX_ALLOCATE_MEMORY_TYPE_ALIGNMENT_NAME(allocator, type, size, alignment, name) (allocator)->allocateMemory(type, size, __FILE__ "::" name, __LINE__, alignment)
580#else // GX_DEBUG_NEW
581#define GX_ALLOCATE_MEMORY_TYPE_ALIGNMENT(allocator, type, size, alignment) (allocator)->allocateMemory(type, size, alignment)
582#define GX_ALLOCATE_MEMORY_TYPE_ALIGNMENT_NAME(allocator, type, size, alignment, name) (allocator)->allocateMemory(type, size, alignment)
583#endif // GX_DEBUG_NEW
584
585//---- 解放
586
590#if GX_DEBUG_NEW
591#define GX_SAFE_FREE_MEMORY(pAddress) { if( (pAddress) ) { GxAllocatorList::getAllocator((void*)(pAddress))->freeMemory((void*)(pAddress), __FILE__, __LINE__); (pAddress) = nullptr; } }
592#define GX_SAFE_FREE_MEMORY_NAME(pAddress, name) { if( (pAddress) ) { GxAllocatorList::getAllocator((void*)(pAddress))->freeMemory((void*)(pAddress), __FILE__ "::" name, __LINE__); (pAddress) = nullptr; } }
593#else // GX_DEBUG_NEW
594#define GX_SAFE_FREE_MEMORY(pAddress) { if( (pAddress) ) { GxAllocatorList::getAllocator((void*)(pAddress))->freeMemory((void*)(pAddress)); (pAddress) = nullptr; } }
595#define GX_SAFE_FREE_MEMORY_NAME(pAddress, name) { if( (pAddress) ) { GxAllocatorList::getAllocator((void*)(pAddress))->freeMemory((void*)(pAddress)); (pAddress) = nullptr; } }
596#endif // GX_DEBUG_NEW
597
602#if GX_DEBUG_NEW
603#define GX_SAFE_FREE_MEMORY_ALLOCATOR(pAddress, allocator) { if( (pAddress) ) { (allocator)->freeMemory((void*)(pAddress), __FILE__, __LINE__); (pAddress) = nullptr; } }
604#define GX_SAFE_FREE_MEMORY_ALLOCATOR_NAME(pAddress, allocator, name) { if( (pAddress) ) { (allocator)->freeMemory((void*)(pAddress), __FILE__ "::" name, __LINE__); (pAddress) = nullptr; } }
605#else // GX_DEBUG_NEW
606#define GX_SAFE_FREE_MEMORY_ALLOCATOR(pAddress, allocator) { if( (pAddress) ) { (allocator)->freeMemory((void*)(pAddress)); (pAddress) = nullptr; } }
607#define GX_SAFE_FREE_MEMORY_ALLOCATOR_NAME(pAddress, allocator, name) { if( (pAddress) ) { (allocator)->freeMemory((void*)(pAddress)); (pAddress) = nullptr; } }
608#endif // GX_DEBUG_NEW
609
610//---- 割り当てサイズ変更
611
617#if GX_DEBUG_NEW
618#define GX_REALLOC_MEMORY(pAddress, size) GxAllocatorList::getAllocator(pAddress)->reallocMemory((void*)(pAddress), size, __FILE__, __LINE__)
619#define GX_REALLOC_MEMORY_NAME(pAddress, size, name) GxAllocatorList::getAllocator(pAddress)->reallocMemory((void*)(pAddress), size, __FILE__ "::" name, __LINE__)
620#else // GX_DEBUG_NEW
621#define GX_REALLOC_MEMORY(pAddress, size) GxAllocatorList::getAllocator(pAddress)->reallocMemory((void*)(pAddress), size)
622#define GX_REALLOC_MEMORY_NAME(pAddress, size, name) GxAllocatorList::getAllocator(pAddress)->reallocMemory((void*)(pAddress), size)
623#endif // GX_DEBUG_NEW
624
625//===========================================================================
627//===========================================================================
629{
630 //-----------------------------------------------------------
632 //-----------------------------------------------------------
634private:
636 constexpr GxScopedTemporaryBuffer(void) : _pAllocator(nullptr), _pAddress(nullptr){}
637public:
639 GxScopedTemporaryBuffer(GxAllocator* pAllocator, u32 size, GxMemory::ALIGNMENT alignment = GxMemory::ALIGNMENT::_16) : _pAllocator(pAllocator)
640 {
641#if GX_DEBUG_NEW
642 _pAddress = _pAllocator->allocateMemory(GxAllocator::ALLOCATE_TYPE_DEFAULT, size, __FILE__, __LINE__, alignment);
643#else // GX_DEBUG_NEW
644 _pAddress = _pAllocator->allocateMemory(GxAllocator::ALLOCATE_TYPE_DEFAULT, size, alignment);
645#endif // !GX_DEBUG_NEW
646 }
649 {
650 if(_pAddress)
651 {
652#if GX_DEBUG_NEW
653 _pAllocator->freeMemory(_pAddress, __FILE__, __LINE__);
654#else // GX_DEBUG_NEW
655 _pAllocator->freeMemory(_pAddress);
656#endif // !GX_DEBUG_NEW
657 _pAddress = nullptr;
658 }
659 }
660
662 //-----------------------------------------------------------
664 //-----------------------------------------------------------
666public:
668 constexpr void* getBuffer(void) const { return _pAddress; }
669
671 //-----------------------------------------------------------
673 //-----------------------------------------------------------
675private:
676 GxAllocator* _pAllocator;
677 void* _pAddress;
678
680};
681
682GX_CORE_NAMESPACE_END()
#define GX_PROHIBIT_CLASS_BASE(__CLASS__)
GxClassBase継承の禁止宣言
Definition GxBase.h:240
void GxTypedObject
その他
Definition GxDefine.h:213
メモリアロケータ基底クラス
Definition GxAllocator.h:82
u32 _size
確保サイズ
Definition GxAllocator.h:219
void initializeAllocateBuffer(void *pAddress, u32 size)
確保メモリ初期化
Definition GxAllocator.h:235
virtual void * allocateMemory(u32 type, u32 size, GxMemory::ALIGNMENT alignment=GxMemory::ALIGNMENT::_16)
メモリ確保
Definition GxAllocator.cpp:546
constexpr u32 getAttribute(void) const
アトリビュート取得
Definition GxAllocator.h:193
GxCriticalSection _criticalSection
クリティカルセクション
Definition GxAllocator.h:217
ATTRIBUTE
属性
Definition GxAllocator.h:95
@ ATTRIBUTE_TRACE
メモリ確保・解放時にログを出力
Definition GxAllocator.h:99
@ ATTRIBUTE_ZERO_CLEAR
確保時に0クリア
Definition GxAllocator.h:96
constexpr void setAttribute(u32 attribute)
アトリビュート設定
Definition GxAllocator.h:195
static constexpr u32 ALLOCATE_TYPE_DEFAULT
ディフォルト値
Definition GxAllocator.h:104
constexpr void * getAddress(void) const
確保アドレス取得
Definition GxAllocator.h:189
void * _pAddress
確保アドレス
Definition GxAllocator.h:218
u32 _attribute
属性
Definition GxAllocator.h:220
GxMemory::TYPE _type
メモリ確保タイプ
Definition GxAllocator.h:221
void terminateAllocateBuffer(void *pAddress, u32 size)
確保メモリ終了
Definition GxAllocator.h:259
constexpr void addAttribute(u32 attribute)
アトリビュート追加
Definition GxAllocator.h:197
constexpr u32 getSize(void) const
確保サイズ取得
Definition GxAllocator.h:191
virtual void freeMemory(void *pAddress)
メモリ解放
Definition GxAllocator.cpp:581
constexpr GxMemory::TYPE getMemoryType(void) const
メモリ確保タイプ取得
Definition GxAllocator.h:199
メモリアロケータリスト
Definition GxAllocator.h:347
~GxAllocatorList(void)
デストラクタ
Definition GxAllocator.h:411
static GxAllocator * getAllocator(const void *pAddress)
アロケータ取得 (確保済みアドレス指定)
Definition GxAllocator.h:438
static constexpr u32 SIZE_REMAIN_ALL
アロケータ確保メモリ残容量全割り当て時指定サイズ定数
Definition GxAllocator.h:397
static void releaseAllocatorList(void)
アロケータリスト破棄
Definition GxAllocator.cpp:250
static GxAllocator * getAllocator(GxAllocatorList::ALLOCATOR_TYPE number)
アロケータ取得 (インデックス指定)
Definition GxAllocator.h:436
static u32 getUserListCount(void)
アロケータリストユーザ追加リスト数取得
Definition GxAllocator.h:447
static void terminate(void)
終了
Definition GxAllocator.cpp:107
static void setType(GxAllocatorList::ALLOCATOR_TYPE number, u32 type)
アロケータ処理タイプ設定
Definition GxAllocator.h:442
static void initialize(const GxCreateInformation *pAllocatorInformation, u32 count)
初期化
Definition GxAllocator.cpp:71
static GxAllocatorList * getAllocatorList(GxAllocatorList::ALLOCATOR_TYPE number)
アロケータリスト取得 (インデックス指定)
Definition GxAllocator.cpp:284
GxAllocatorList(void)
コンストラクタ
Definition GxAllocator.cpp:57
ALLOCATOR_TYPE
アロケータ定義
Definition GxAllocator.h:355
@ MAX
定義アロケータ数
@ PHYSICS
物理エンジン
@ SYSTEM_MAX
システム定義アロケータ数
@ RENDER
レンダリング
@ USER_START
ユーザー定義アロケータ開始
@ INVALID
未設定アロケータリスト番号
static void getAllAllocator(GxArrayClassBase &dst)
全アロケータ取得
Definition GxAllocator.cpp:304
constexpr GxAllocator * getAllocator(void) const
アロケータメンバ取得
Definition GxAllocator.h:463
static void attach(GxAllocatorList::ALLOCATOR_TYPE number, GxAllocator *pAllocator, u32 type=0)
アロケータリストへの登録
Definition GxAllocator.cpp:415
static u32 getHardwareReservedMemoryTotal(void)
ハードウェア側消費用予約メモリ合計サイズ取得
Definition GxAllocator.cpp:355
static u64 getAllAllocatorMemorySize(void)
リスト内アロケータのメモリ総確保量を取得
Definition GxAllocator.cpp:338
static u64 getAvailableMemoryBeforeCreateAllocator(void)
アロケータリスト生成前確保可能システムメモリ容量取得(CPU,VRAM確保前)
Definition GxAllocator.h:450
static u32 getHardwareReservedMemoryFree(void)
ハードウェア側消費用予約メモリ空きサイズ取得
Definition GxAllocator.cpp:385
static u32 getCount(void)
アロケータリスト総数取得 (システム予約 + ユーザ追加)
Definition GxAllocator.h:445
static b32 createAllocatorList(const GxCreateInformation *pAllocatorInformation, u32 count)
アロケータリスト生成
Definition GxAllocator.cpp:126
constexpr u32 getType(void) const
処理タイプメンバ取得
Definition GxAllocator.h:465
static u64 getAvailableMemoryAfterCreateAllocator(void)
アロケータリスト生成後確保可能システムメモリ容量取得(VRAM確保前)
Definition GxAllocator.h:452
static GxAllocator * detach(GxAllocatorList::ALLOCATOR_TYPE number)
アロケータリストからの解除 (インデックス指定)
Definition GxAllocator.cpp:430
static u32 getType(GxAllocatorList::ALLOCATOR_TYPE number)
アロケータ処理タイプ取得
Definition GxAllocator.h:440
static u32 getHardwareReservedMemoryUsed(void)
ハードウェア側消費用予約メモリ消費サイズ取得
Definition GxAllocator.cpp:369
配列クラス
Definition GxArrayClassBase.h:18
オブジェクト基底クラス
Definition GxBase.h:88
クリティカルセクションクラス
Definition GxThread.h:20
ALIGNMENT
メモリアライメント定義
Definition GxMemory.h:51
@ _16
16byteアライメント
Definition GxMemory.h:54
TYPE
割り当てメモリ種別
Definition GxMemory.h:30
プロパティクラス
Definition GxProperty.h:48
実行時型情報クラス
Definition GxRtti.h:154
一時確保バッファクラス (※スコープ外で自動解放)
Definition GxAllocator.h:629
~GxScopedTemporaryBuffer(void)
デストラクタ
Definition GxAllocator.h:648
constexpr void * getBuffer(void) const
確保バッファアドレス取得
Definition GxAllocator.h:668
GxScopedTemporaryBuffer(GxAllocator *pAllocator, u32 size, GxMemory::ALIGNMENT alignment=GxMemory::ALIGNMENT::_16)
コンストラクタ
Definition GxAllocator.h:639
アロケータ生成情報
Definition GxAllocator.h:385
GxAllocatorList::ALLOCATOR_TYPE _share
共有アロケータタイプ(ALLOCATOR_TYPE)
Definition GxAllocator.h:386
u64 _size
確保メモリサイズ (0の場合:共有指定が必要, SIZE_REMAIN_ALLの場合:残容量割り当て)
Definition GxAllocator.h:388
u32 _attribute
アロケータ属性
Definition GxAllocator.h:390
u32 _allocatorType
アロケータ指定確保タイプ
Definition GxAllocator.h:387
GxMemory::TYPE _memoryType
確保メモリタイプ (TYPE_UNKNOWNの場合:システムにお任せ ※一部のアロケータタイプはシステム固定なので無視されます)
Definition GxAllocator.h:389
Definition GxColor.h:21
32bitブーリアン
Definition GxDefine.h:173