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*) {} \
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__); } \
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*) {}
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*) {} \
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); } \
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*) {}
73GX_CORE_NAMESPACE_BEGIN()
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)
104 static constexpr u32 ALLOCATE_TYPE_DEFAULT = 0;
107#if GX_DEVELOP && defined(_DEBUG)
109 static constexpr u8 FILL_MAGIC_NUMBER = 0xcd;
137 virtual void freeMemory(
void* pAddress, GX_CSTR filename, u32 line);
139 virtual void* reallocMemory(
void* pAddress, u32 size, GX_CSTR filename, u32 line);
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);
150 virtual b32 isValidAddr(
const void* pAddress);
157 virtual void printInformation(
void);
166 void initializeAllocateBuffer(
void* pAddress, u32 size);
168 void terminateAllocateBuffer(
void* pAddress, u32 size);
173 b32 isValidAllocateBuffer(
const void* pAddress, u32 size)
const;
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;
191 constexpr u32
getSize(
void)
const {
return _size; }
197 constexpr void addAttribute(u32 attribute) { _attribute |= attribute; }
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; }
242 GX_MEMSET(pAddress, 0, size);
244#if GX_DEVELOP && defined(_DEBUG)
248 GX_MEMSET(pAddress, FILL_MAGIC_NUMBER, size);
261#if GX_DEVELOP && defined(_DEBUG)
265 GX_MEMSET(pAddress, FILL_MAGIC_NUMBER, size);
282GX_FORCE_INLINE
b32 GxAllocator::isValidAllocateBuffer(
const void* pAddress, u32 size)
const
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)
293 if( GX_MEMCMP(pPointer, &check,
sizeof(u8)) )
295 GX_ASSERT(
false,
"isValidAllocateBuffer Error!! addr(0x%p) is not valid value(0x%x)", pPointer, *pPointer);
312GX_FORCE_INLINE
void GxAllocator::traceAllocateInformation(
const void* pAddress, u32 size, GX_CSTR filename, u32 line)
const
316 GX_TRACE(GX_TRACE_CATEGORY_CORE,
"[allocate] addr=0x%p size=%d", pAddress, size);
319 GX_TRACE(GX_TRACE_CATEGORY_CORE,
" %s (%d)", filename, line);
330GX_FORCE_INLINE
void GxAllocator::traceFreeInformation(
const void* pAddress, GX_CSTR filename, u32 line)
const
334 GX_TRACE(GX_TRACE_CATEGORY_CORE,
"[free] addr=0x%p", pAddress);
337 GX_TRACE(GX_TRACE_CATEGORY_CORE,
" %s (%d)", filename, line);
413 static void initialize(
const GxCreateInformation* pAllocatorInformation, u32 count);
465 constexpr u32
getType(
void)
const {
return _type; }
468 constexpr void setName(GX_CSTR name) { _name = name; }
470 constexpr GX_CSTR getName(
void)
const {
return _name; }
490 static void printInformation(
void);
509 static u32 _userAllocatorListCount;
510 static u64 _availableMemoryBeforeCreateAllocator;
511 static u64 _availableMemoryAfterCreateAllocator;
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__)
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)
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)
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)
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__)
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)
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)
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)
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; } }
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; } }
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; } }
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; } }
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__)
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)
653 _pAllocator->
freeMemory(_pAddress, __FILE__, __LINE__);
668 constexpr void*
getBuffer(
void)
const {
return _pAddress; }
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
@ USER_START
ユーザー定義アロケータ開始
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
32bitブーリアン
Definition GxDefine.h:173