CommonLibSSE NG
bhkThreadMemorySource.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "RE/I/IMemoryHeap.h"
5 
6 namespace RE
7 {
8  class HeapBlock;
9  class HeapBlockFreeHead;
10 
12  public hkMemoryAllocator, // 00
13  public IMemoryHeap // 08
14  {
15  public:
16  inline static constexpr auto RTTI = RTTI_bhkThreadMemorySource;
17 
18  struct FreeBlock
19  {
20  public:
21  // members
22  FreeBlock* next; // 0
23  };
24  static_assert(sizeof(FreeBlock) == 0x8);
25 
26  struct BlockPage
27  {
28  public:
29  // members
30  BlockPage* left; // 00
31  BlockPage* right; // 08
32  FreeBlock* blocks; // 10
33  std::uint16_t totalElem; // 18
34  std::uint16_t freeElem; // 1A
35  std::uint32_t pad1C; // 1C
36  };
37  static_assert(sizeof(BlockPage) == 0x20);
38 
39  struct Row
40  {
41  public:
42  // members
45  std::int32_t totalFreeBlocks; // 10
46  std::int32_t totalAllocatedBlocks; // 14
47  std::int32_t totalBytes; // 18
48  std::int32_t elemSize; // 1C
49  };
50  static_assert(sizeof(Row) == 0x20);
51 
53  {
54  public:
55  // members
56  char mem[sizeof(BlockPage[255]) * 256]; // 000000
57  BlockPage blockPages[255]; // 1FE000
58  MegaBlockPage* left; // 1FFFE0
59  MegaBlockPage* right; // 1FFFE8
61  std::uint16_t numFreeBlockPages; // 1FFFF8
62  std::uint16_t nextBlockPageAlloc; // 1FFFFA
63  bool decommitted; // 1FFFFC
64  std::uint8_t pad1FFFFD; // 1FFFFD
65  std::uint16_t pad1FFFFE; // 1FFFFE
66  };
67  static_assert(sizeof(MegaBlockPage) == 0x200000);
68 
69  ~bhkThreadMemorySource() override; // 00
70 
71  // override (hkMemoryAllocator)
72  void* BlockAlloc(std::int32_t a_numBytes) override; // 01
73  void BlockFree(void* a_ptr, std::int32_t a_numBytes) override; // 02
74  void* BufAlloc(std::int32_t& a_reqNumBytesInOut) override; // 03
75  void BufFree(void* a_ptr, std::int32_t a_numBytes) override; // 04
76  void* BufRealloc(void* a_ptrOld, std::int32_t a_oldNumBytes, std::int32_t& a_reqNumBytesInOut) override; // 05
77  void BlockAllocBatch(void** a_ptrsOut, std::int32_t a_numPtrs, std::int32_t a_blockSize) override; // 06
78  void BlockFreeBatch(void** a_ptrsIn, std::int32_t a_numPtrs, std::int32_t a_blockSize) override; // 07
79  void GetMemoryStatistics(MemoryStatistics& a_usage) override; // 08
80  std::int32_t GetAllocatedSize(const void* a_obj, std::int32_t a_numBytes) override; // 09
81 
82  // override (IMemoryHeap)
83  std::size_t Size(const void* a_block) const override; // 01
84  void GetMemoryStats(MemoryStats* a_stats) override; // 02
85  const char* GetName() const override; // 07 - { return "bhkThreadMemorySource"; }
86  void* Allocate(std::size_t a_size, std::uint32_t a_alignment) override; // 08
87  void Deallocate(void* a_pointer, std::uint32_t) override; // 09
88  bool PointerInHeap(const void* a_pointer) const override; // 0A
89  std::size_t TotalSize(const void* a_pointer) const override; // 0B
90  void GetHeapStats(HeapStats* a_stats, bool a_fullBlockInfo) override; // 0C
91  bool ShouldTrySmallBlockPools(std::size_t a_size, MEM_CONTEXT a_context) override; // 0D
92  [[nodiscard]] std::uint32_t GetPageSize() const override; // 0E
93 
94  // members
96  Row* rows; // 38
97  std::uint16_t* smallRowIndexes; // 40
98  std::uint16_t* largeRowIndexes; // 48
99  HeapBlock** lists; // 50
103  void* memoryRoot; // 70
104  char* allocBase; // 78
105  char* blockStart; // 80
106  char* allocEnd; // 88
107  char* commitEnd; // 90
108  char* blockPageCommit; // 98
109  char* addressSpaceEnd; // A0
112  std::int32_t addressSpaceSize; // B8
113  std::int32_t totalFreeBlockPages; // BC
114  std::uint32_t usedRows; // C0
115  std::int32_t totalAllocated; // C4
116  std::int32_t totalFreeBlocks; // C8
117  std::int32_t totalBlocks; // CC
118  bool allowDecommits; // D0
119  std::uint8_t padD1; // D1
120  std::uint16_t padD2; // D2
121  std::uint32_t padD4; // D4
122  };
123  static_assert(sizeof(bhkThreadMemorySource) == 0xD8);
124 }
Definition: BSAtomic.h:8
Definition: HeapBlockFreeHead.h:8
Definition: HeapBlock.h:6
Definition: IMemoryHeap.h:31
Definition: bhkThreadMemorySource.h:14
void BlockAllocBatch(void **a_ptrsOut, std::int32_t a_numPtrs, std::int32_t a_blockSize) override
void * Allocate(std::size_t a_size, std::uint32_t a_alignment) override
char * commitEnd
Definition: bhkThreadMemorySource.h:107
HeapBlock * lastBlock
Definition: bhkThreadMemorySource.h:102
char * allocEnd
Definition: bhkThreadMemorySource.h:106
bool PointerInHeap(const void *a_pointer) const override
HeapBlockFreeHead * largeFreeTrees
Definition: bhkThreadMemorySource.h:100
char * addressSpaceEnd
Definition: bhkThreadMemorySource.h:109
void BlockFreeBatch(void **a_ptrsIn, std::int32_t a_numPtrs, std::int32_t a_blockSize) override
void BlockFree(void *a_ptr, std::int32_t a_numBytes) override
std::uint32_t usedRows
Definition: bhkThreadMemorySource.h:114
std::size_t Size(const void *a_block) const override
void Deallocate(void *a_pointer, std::uint32_t) override
~bhkThreadMemorySource() override
static constexpr auto RTTI
Definition: bhkThreadMemorySource.h:16
bool ShouldTrySmallBlockPools(std::size_t a_size, MEM_CONTEXT a_context) override
HeapBlock ** lists
Definition: bhkThreadMemorySource.h:99
bool allowDecommits
Definition: bhkThreadMemorySource.h:118
void BufFree(void *a_ptr, std::int32_t a_numBytes) override
std::uint32_t padD4
Definition: bhkThreadMemorySource.h:121
std::int32_t totalFreeBlockPages
Definition: bhkThreadMemorySource.h:113
std::int32_t addressSpaceSize
Definition: bhkThreadMemorySource.h:112
char * blockPageCommit
Definition: bhkThreadMemorySource.h:108
void * BufRealloc(void *a_ptrOld, std::int32_t a_oldNumBytes, std::int32_t &a_reqNumBytesInOut) override
void * BlockAlloc(std::int32_t a_numBytes) override
std::uint16_t * largeRowIndexes
Definition: bhkThreadMemorySource.h:98
Row * rows
Definition: bhkThreadMemorySource.h:96
BSCriticalSection lock
Definition: bhkThreadMemorySource.h:95
void * memoryRoot
Definition: bhkThreadMemorySource.h:103
void GetMemoryStats(MemoryStats *a_stats) override
const char * GetName() const override
std::int32_t GetAllocatedSize(const void *a_obj, std::int32_t a_numBytes) override
MegaBlockPage * currMegaBlockPageAlloc
Definition: bhkThreadMemorySource.h:111
std::uint32_t GetPageSize() const override
char * blockStart
Definition: bhkThreadMemorySource.h:105
std::size_t TotalSize(const void *a_pointer) const override
std::int32_t totalBlocks
Definition: bhkThreadMemorySource.h:117
char * allocBase
Definition: bhkThreadMemorySource.h:104
std::int32_t totalFreeBlocks
Definition: bhkThreadMemorySource.h:116
void GetMemoryStatistics(MemoryStatistics &a_usage) override
std::uint16_t * smallRowIndexes
Definition: bhkThreadMemorySource.h:97
void * BufAlloc(std::int32_t &a_reqNumBytesInOut) override
std::int32_t totalAllocated
Definition: bhkThreadMemorySource.h:115
MegaBlockPage * megaBlockPageList
Definition: bhkThreadMemorySource.h:110
std::uint8_t padD1
Definition: bhkThreadMemorySource.h:119
HeapBlock * firstBlock
Definition: bhkThreadMemorySource.h:101
std::uint16_t padD2
Definition: bhkThreadMemorySource.h:120
void GetHeapStats(HeapStats *a_stats, bool a_fullBlockInfo) override
Definition: hkMemoryAllocator.h:8
Definition: AbsorbEffect.h:6
constexpr REL::VariantID RTTI_bhkThreadMemorySource(690931, 398786, 0x1f691a8)
Definition: IMemoryHeap.h:10
Definition: IMemoryStoreBase.h:6
Definition: bhkThreadMemorySource.h:27
std::uint32_t pad1C
Definition: bhkThreadMemorySource.h:35
BlockPage * right
Definition: bhkThreadMemorySource.h:31
BlockPage * left
Definition: bhkThreadMemorySource.h:30
FreeBlock * blocks
Definition: bhkThreadMemorySource.h:32
std::uint16_t totalElem
Definition: bhkThreadMemorySource.h:33
std::uint16_t freeElem
Definition: bhkThreadMemorySource.h:34
Definition: bhkThreadMemorySource.h:19
FreeBlock * next
Definition: bhkThreadMemorySource.h:22
Definition: bhkThreadMemorySource.h:53
std::uint8_t pad1FFFFD
Definition: bhkThreadMemorySource.h:64
bool decommitted
Definition: bhkThreadMemorySource.h:63
BlockPage blockPages[255]
Definition: bhkThreadMemorySource.h:57
char mem[sizeof(BlockPage[255]) *256]
Definition: bhkThreadMemorySource.h:56
BlockPage * freeBlockPages
Definition: bhkThreadMemorySource.h:60
std::uint16_t pad1FFFFE
Definition: bhkThreadMemorySource.h:65
std::uint16_t nextBlockPageAlloc
Definition: bhkThreadMemorySource.h:62
std::uint16_t numFreeBlockPages
Definition: bhkThreadMemorySource.h:61
MegaBlockPage * left
Definition: bhkThreadMemorySource.h:58
MegaBlockPage * right
Definition: bhkThreadMemorySource.h:59
Definition: bhkThreadMemorySource.h:40
std::int32_t totalAllocatedBlocks
Definition: bhkThreadMemorySource.h:46
std::int32_t elemSize
Definition: bhkThreadMemorySource.h:48
BlockPage * pageList
Definition: bhkThreadMemorySource.h:43
BlockPage * currAlloc
Definition: bhkThreadMemorySource.h:44
std::int32_t totalFreeBlocks
Definition: bhkThreadMemorySource.h:45
std::int32_t totalBytes
Definition: bhkThreadMemorySource.h:47
Definition: hkMemoryAllocator.h:22