CommonLibSSE NG
ScrapHeap.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "RE/I/IMemoryStore.h"
4 
5 #include "REX/W32/KERNEL32.h"
6 
7 namespace RE
8 {
9  class ScrapHeap : public IMemoryStore
10  {
11  public:
12  inline static constexpr auto RTTI = RTTI_ScrapHeap;
13 
14  struct Block
15  {
16  public:
17  // members
18  std::size_t sizeFlags; // 00
19  Block* prev; // 08
20  };
21  static_assert(sizeof(Block) == 0x10);
22 
23  struct FreeBlock : public Block
24  {
25  public:
26  // members
27  FreeBlock* left; // 10
28  FreeBlock* right; // 18
29  };
30  static_assert(sizeof(FreeBlock) == 0x20);
31 
32  struct FreeTreeNode : public Block
33  {
34  public:
35  // members
36  FreeTreeNode** root; // 10
39  std::size_t parentAndBlack; // 28
40  };
41  static_assert(sizeof(FreeTreeNode) == 0x30);
42 
44 
45  // override (IMemoryStore)
46  std::size_t Size(void const* a_mem) const override { return *static_cast<const std::size_t*>(a_mem) & ~(std::size_t{ 3 } << 62); } // 01
47  void GetMemoryStats(MemoryStats*) override { return; } // 02
48  bool ContainsBlockImpl(const void* a_block) const override { return baseAddress <= a_block && a_block <= endAddress; } // 03
49  void* AllocateAlignImpl(std::size_t a_size, std::uint32_t a_alignment) override { return Allocate(a_size, a_alignment); } // 04
50  void DeallocateAlignImpl(void*& a_block) override { Deallocate(a_block), a_block = nullptr; } // 05
51 
52  void* Allocate(std::size_t a_size, std::size_t a_alignment);
53  void Deallocate(void* a_mem);
54 
55  // members
56  FreeBlock* smallBlocks[6]{ nullptr }; // 08
57  FreeTreeNode* freeList{ nullptr }; // 38
58  Block* lastBlock{ nullptr }; // 40
59  void* baseAddress{ nullptr }; // 48
60  void* endAddress{ nullptr }; // 50
61  void* commitEnd{ nullptr }; // 58
62  std::size_t reserveSize{ 1 << 26 }; // 60
63  std::size_t minCommit{ 1 << 17 }; // 68
64  std::size_t totalAllocated{ 0 }; // 70
65  std::uint32_t keepPagesRequest{ 0 }; // 78
66  std::uint32_t totalFreeBlocks{ 0 }; // 7C
67  std::uint32_t freeSmallBlocks{ 0 }; // 80
68  std::uint32_t totalAllocatedBlocks{ 0 }; // 84
69  std::uint32_t pmpBarrier{ 0 }; // 88
70  };
71  static_assert(sizeof(ScrapHeap) == 0x90);
72 }
Definition: IMemoryStore.h:8
Definition: ScrapHeap.h:10
~ScrapHeap() override
Definition: ScrapHeap.h:43
std::size_t Size(void const *a_mem) const override
Definition: ScrapHeap.h:46
void Deallocate(void *a_mem)
bool ContainsBlockImpl(const void *a_block) const override
Definition: ScrapHeap.h:48
std::uint32_t pmpBarrier
Definition: ScrapHeap.h:69
std::size_t reserveSize
Definition: ScrapHeap.h:62
void * AllocateAlignImpl(std::size_t a_size, std::uint32_t a_alignment) override
Definition: ScrapHeap.h:49
std::uint32_t freeSmallBlocks
Definition: ScrapHeap.h:67
Block * lastBlock
Definition: ScrapHeap.h:58
std::uint32_t keepPagesRequest
Definition: ScrapHeap.h:65
static constexpr auto RTTI
Definition: ScrapHeap.h:12
std::size_t totalAllocated
Definition: ScrapHeap.h:64
FreeTreeNode * freeList
Definition: ScrapHeap.h:57
std::uint32_t totalAllocatedBlocks
Definition: ScrapHeap.h:68
std::uint32_t totalFreeBlocks
Definition: ScrapHeap.h:66
void * baseAddress
Definition: ScrapHeap.h:59
std::size_t minCommit
Definition: ScrapHeap.h:63
void * commitEnd
Definition: ScrapHeap.h:61
void GetMemoryStats(MemoryStats *) override
Definition: ScrapHeap.h:47
void * endAddress
Definition: ScrapHeap.h:60
FreeBlock * smallBlocks[6]
Definition: ScrapHeap.h:56
void * Allocate(std::size_t a_size, std::size_t a_alignment)
void DeallocateAlignImpl(void *&a_block) override
Definition: ScrapHeap.h:50
bool VirtualFree(void *a_address, std::size_t a_size, std::uint32_t a_type) noexcept
constexpr auto MEM_RELEASE
Definition: KERNEL32.h:18
Definition: AbsorbEffect.h:6
constexpr REL::VariantID RTTI_ScrapHeap(690278, 398133, 0x1f5f460)
Definition: IMemoryStoreBase.h:6
Definition: ScrapHeap.h:15
Block * prev
Definition: ScrapHeap.h:19
std::size_t sizeFlags
Definition: ScrapHeap.h:18
Definition: ScrapHeap.h:24
FreeBlock * right
Definition: ScrapHeap.h:28
FreeBlock * left
Definition: ScrapHeap.h:27
Definition: ScrapHeap.h:33
FreeTreeNode * leftNode
Definition: ScrapHeap.h:37
std::size_t parentAndBlack
Definition: ScrapHeap.h:39
FreeTreeNode * rightNode
Definition: ScrapHeap.h:38
FreeTreeNode ** root
Definition: ScrapHeap.h:36