13GX_CORE_NAMESPACE_BEGIN()
31 static constexpr u32 HEAP_SHIFT = 4;
32 static constexpr u32 BLOCK_SIZE = (1 << HEAP_SHIFT);
33 static constexpr u32 HASH_TABLE_THRESHOLD= 16;
34 static constexpr u32 HASH_TABLE_NUM = 40;
35 static constexpr u32 HEAP_MAGIC_NUMBER = GX_FOURCC(
'h',
'e',
'a',
'p');
66 _magic = HEAP_MAGIC_NUMBER;
67 _pAllocator = pAllocator;
87 void setAnnotation(GX_CSTR name);
89 GX_CSTR getAnnotation(
void)
const;
91 u32 getAnnotationLength(
void)
const;
94 GX_CSTR getFilename(GX_STR buffer, u32 bufferSize)
const;
97 GX_CSTR getName(GX_STR buffer, u32 bufferSize)
const;
117#if defined(_WINDOWS) || defined(_PS4) || defined(_PS5) || defined(_XBOX_XS)
155 static GxAllocatorHeap* create(GX_CSTR name,
void* pAddress, u32 size);
161 void initialize(
void* pAddress, u32 size);
173 void freeMemory(
void* pAddress, GX_CSTR filename, u32 line)
override;
175 void* reallocMemory(
void* pAddress, u32 size, GX_CSTR filename, u32 line)
override;
177 void allocateDummyMemory(
void);
179 void freeDummyMemory(
void);
182 void* allocateMemory(u32 type, u32 size, GxMemory::ALIGNMENT alignment = GxMemory::ALIGNMENT::_16) override;
184 void freeMemory(
void* pAddress)
override;
186 void* reallocMemory(
void* pAddress, u32 size)
override;
192 void printInformation(
void)
override;
194 constexpr void setDebugAllocator(
GxAllocatorHeap* pAllocator) { _pDebugAllocator = pAllocator; }
196 static void traceCallStackAddToString(
const GxHeapInformation* pHeapInformation,
GxString& message);
198 static void traceCallStack(
const GxHeapInformation* pHeapInformation);
201 void dumpToCsv(
void);
206 b32 isValid(
const GxHeapInformation* pHeapInformation)
const;
211 void traceAllocateInformation(
const void* pAddress, u32 size, GX_CSTR filename =
nullptr, u32 line = 0)
const override;
213 void traceFreeInformation(
const void* pAddress, GX_CSTR filename =
nullptr, u32 line = 0)
const override;
218 void* allocateMemoryFastDebug(u32 size, GX_CSTR filename, u32 line,
GxMemory::ALIGNMENT alignment);
220 void* allocateMemoryForwardDebug(u32 size, GX_CSTR filename, u32 line,
GxMemory::ALIGNMENT alignment);
222 void* allocateMemoryBackDebug(u32 size, GX_CSTR filename, u32 line,
GxMemory::ALIGNMENT alignment);
225 void* allocateMemoryFast(u32 size, GxMemory::ALIGNMENT alignment);
232 void insertHeap(GxHeapInformation* pBaseHeap, GxHeapInformation* pInsertHeap);
234 void linkFreeHeapList(GxHeapInformation* pFreeHeap);
236 u32 getHashValue(u32 value)
const;
246 void addHeapDebugInformation(
GxHeapInformation* pAddress, u32 serialNumber, GX_CSTR filename =
nullptr, u32 line = 0);
248 void checkMemoryLeak(
void);
260 u32 getFreeMax(
void)
const;
268 constexpr u32 getUsedSizeMax(
void)
const {
return _usedSizeMax; }
270 constexpr void clearUsedSizeMax(
void) { _usedSizeMax = _usedSize; }
272 constexpr void setCallStackMax(u32 count) { _callStackMax = count; }
274 constexpr u32 getCallStackMax(
void)
const {
return _callStackMax; }
276 GX_FORCE_INLINE
void updateMaxAvailableSize(
void) { _maxFreeSize = getMaxAvailableSize(); }
278 constexpr u32 getWalkFreeMax(
void)
const {
return _walkFreeMax; }
280 constexpr void setUsedSizeDiff(
void) { _usedSizeSave = _usedSize; }
282 constexpr s32 getUsedSizeDiff(
void)
const {
return static_cast<s32
>(
static_cast<s64
>(_usedSize) -
static_cast<s64
>(_usedSizeSave)); }
284 constexpr u32 getSerialNumber(
void)
const {
return _serialNumber; }
290 static GxHeapInformation* getHeaderPointer(
void* pAddress);
292 static u32 getBlockFromSize(u32 size);
294 static u32 getSizeFromBlock(u32 block);
296 static u32 getHeaderSize(
void);
301 void getPropertyUsedSizeDiff(
void*
const pValue)
const { *
static_cast<s32*
>(pValue) = getUsedSizeDiff(); }
310 GxHeapInformation* _pHeapTop;
311 GxHeapInformation* _pHeapLast;
312 GxHeapInformation _freeTop[HASH_TABLE_NUM + 1];
314 b32 _isBufferAllocated;
319 u32 _assertSerialNumber;
321 u32 _allocateDummyMemorySize;
339GX_FORCE_INLINE
void GxAllocatorHeap::traceAllocateInformation(
const void* pAddress, u32 size, GX_CSTR filename, u32 line)
const
345 GX_TRACE(GX_TRACE_CATEGORY_CORE,
"[heapAllocate] <%s> addr(0x%p) size(%d) : HeapAddr(0x%p) usedSize(%d) freeSize(%d) Prev(0x%p) Next(0x%p) PrevFree(0x%p) NextFree(0x%p)", getAllocatorName(), pAddress, size, pHeader,
getSizeFromBlock(pHeader->_usedBlock),
getSizeFromBlock(pHeader->_freeBlock), pHeader->_pPrevious, pHeader->_pNext, pHeader->_pPreviousFree, pHeader->_pNextFree);
350 GX_TRACE(GX_TRACE_CATEGORY_CORE,
" %s (%d)", filename, line);
351 GX_TRACE(GX_TRACE_CATEGORY_CORE,
" serial[%d]", pHeader->_serialNumber);
362GX_FORCE_INLINE
void GxAllocatorHeap::traceFreeInformation(
const void* pAddress, GX_CSTR filename, u32 line)
const
368 GX_TRACE(GX_TRACE_CATEGORY_CORE,
"[heapFree] <%s> addr(0x%p) : HeapAddr(0x%p) usedSize(%d) freeSize(%d) Prev(0x%p) Next(0x%p) PrevFree(0x%p) NextFree(0x%p)",
369 getAllocatorName(), pAddress, pHeader,
getSizeFromBlock(pHeader->_usedBlock),
getSizeFromBlock(pHeader->_freeBlock), pHeader->_pPrevious, pHeader->_pNext, pHeader->_pPreviousFree, pHeader->_pNextFree);
374 GX_TRACE(GX_TRACE_CATEGORY_CORE,
" %s (%d)", filename, line);
375 GX_TRACE(GX_TRACE_CATEGORY_CORE,
" serial[%d]", pHeader->_serialNumber);
376 GX_TRACE(GX_TRACE_CATEGORY_CORE,
" %s (%d)", pHeader->getAnnotation(), pHeader->_line);
389 return reinterpret_cast<void*
>(
reinterpret_cast<size_t>(pHeapInformation) +
getHeaderSize());
409 GX_ASSERT(
GxMath::isAlignmentFast(size, BLOCK_SIZE),
"argument error!! size(%d) is not alignment BLOCK_SIZE(%d)", size, BLOCK_SIZE);
410 return ((size + BLOCK_SIZE - 1) >> HEAP_SHIFT);
420 return (block << HEAP_SHIFT);
432GX_CORE_NAMESPACE_END()
#define GX_PROHIBIT_CLASS_BASE(__CLASS__)
GxClassBase継承の禁止宣言
Definition GxBase.h:240
ヒープメモリアロケータ
Definition GxAllocatorHeap.h:19
static GxHeapInformation * getHeaderPointer(void *pAddress)
確保メモリからヘッダーポインタ取得
Definition GxAllocatorHeap.h:397
static u32 getHeaderSize(void)
ヘッダーサイズ取得 (※BLOCK_SIZEでのアライメント考慮)
Definition GxAllocatorHeap.h:427
static u32 getBlockFromSize(u32 size)
サイズ → ブロック数取得
Definition GxAllocatorHeap.h:407
GxAllocatorHeap(void)
デフォルトコンストラクタ (使用禁止)
Definition GxAllocatorHeap.h:142
void calculateMaxAvailableSize(void)
最大確保可能サイズの計算
static u32 getSizeFromBlock(u32 block)
ブロック数 → サイズ取得
Definition GxAllocatorHeap.h:418
ALLOCATE_TYPE
メモリ確保手法
Definition GxAllocatorHeap.h:40
constexpr u32 getUsedSize(void) const
使用サイズの取得
Definition GxAllocatorHeap.h:258
static void * getMemoryPointer(const GxAllocatorHeap::GxHeapInformation *pHeapInformation)
ヘッダーポインタから確保メモリを取得
Definition GxAllocatorHeap.h:387
constexpr GxHeapInformation * getHeapTop(void) const
ヒープ先頭アドレスの取得
Definition GxAllocatorHeap.h:264
メモリアロケータ基底クラス
Definition GxAllocator.h:82
@ ATTRIBUTE_TRACE
メモリ確保・解放時にログを出力
Definition GxAllocator.h:99
u32 _attribute
属性
Definition GxAllocator.h:220
連結リストクラス
Definition GxList.h:18
static GX_FORCE_INLINE T getRoundUpFast(T value, size_t alignment)
数値切り上げ(高速版 ※2のべき乗指定)
Definition GxMath.h:537
static GX_FORCE_INLINE b32 isAlignmentFast(T value, u32 alignment)
アライメント判定(高速版 ※2のべき乗指定)
Definition GxMath.h:500
ALIGNMENT
メモリアライメント定義
Definition GxMemory.h:51
@ _16
16byteアライメント
Definition GxMemory.h:54
TYPE
割り当てメモリ種別
Definition GxMemory.h:30
文字列型クラス
Definition GxString.h:18
32bitブーリアン
Definition GxDefine.h:173