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