CommonLibVR
Loading...
Searching...
No Matches
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
7namespace RE
8{
9 class ScrapHeap : public IMemoryStore
10 {
11 public:
12 inline static constexpr auto RTTI = RTTI_ScrapHeap;
13 inline static constexpr auto VTABLE = VTABLE_ScrapHeap;
14
15 struct Block
16 {
17 public:
18 // members
19 std::size_t sizeFlags; // 00
20 Block* prev; // 08
21 };
22 static_assert(sizeof(Block) == 0x10);
23
24 struct FreeBlock : public Block
25 {
26 public:
27 // members
30 };
31 static_assert(sizeof(FreeBlock) == 0x20);
32
33 struct FreeTreeNode : public Block
34 {
35 public:
36 // members
40 std::size_t parentAndBlack; // 28
41 };
42 static_assert(sizeof(FreeTreeNode) == 0x30);
43
45
46 // override (IMemoryStore)
47 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
48 void GetMemoryStats(MemoryStats*) override { return; } // 02
49 bool ContainsBlockImpl(const void* a_block) const override { return baseAddress <= a_block && a_block <= endAddress; } // 03
50 void* AllocateAlignImpl(std::size_t a_size, std::uint32_t a_alignment) override { return Allocate(a_size, a_alignment); } // 04
51 void DeallocateAlignImpl(void*& a_block) override { Deallocate(a_block), a_block = nullptr; } // 05
52
53 void* Allocate(std::size_t a_size, std::size_t a_alignment);
54 void Deallocate(void* a_mem);
55
56 // members
57 FreeBlock* smallBlocks[6]{ nullptr }; // 08
58 FreeTreeNode* freeList{ nullptr }; // 38
59 Block* lastBlock{ nullptr }; // 40
60 void* baseAddress{ nullptr }; // 48
61 void* endAddress{ nullptr }; // 50
62 void* commitEnd{ nullptr }; // 58
63 std::size_t reserveSize{ 1 << 26 }; // 60
64 std::size_t minCommit{ 1 << 17 }; // 68
65 std::size_t totalAllocated{ 0 }; // 70
66 std::uint32_t keepPagesRequest{ 0 }; // 78
67 std::uint32_t totalFreeBlocks{ 0 }; // 7C
68 std::uint32_t freeSmallBlocks{ 0 }; // 80
69 std::uint32_t totalAllocatedBlocks{ 0 }; // 84
70 std::uint32_t pmpBarrier{ 0 }; // 88
71 };
72 static_assert(sizeof(ScrapHeap) == 0x90);
73}
Definition IMemoryStore.h:8
Definition ScrapHeap.h:10
~ScrapHeap() override
Definition ScrapHeap.h:44
void * Allocate(std::size_t a_size, std::size_t a_alignment)
std::size_t Size(void const *a_mem) const override
Definition ScrapHeap.h:47
void Deallocate(void *a_mem)
bool ContainsBlockImpl(const void *a_block) const override
Definition ScrapHeap.h:49
void * AllocateAlignImpl(std::size_t a_size, std::uint32_t a_alignment) override
Definition ScrapHeap.h:50
std::uint32_t pmpBarrier
Definition ScrapHeap.h:70
std::size_t reserveSize
Definition ScrapHeap.h:63
std::uint32_t freeSmallBlocks
Definition ScrapHeap.h:68
Block * lastBlock
Definition ScrapHeap.h:59
std::uint32_t keepPagesRequest
Definition ScrapHeap.h:66
static constexpr auto RTTI
Definition ScrapHeap.h:12
std::size_t totalAllocated
Definition ScrapHeap.h:65
static constexpr auto VTABLE
Definition ScrapHeap.h:13
FreeTreeNode * freeList
Definition ScrapHeap.h:58
std::uint32_t totalAllocatedBlocks
Definition ScrapHeap.h:69
std::uint32_t totalFreeBlocks
Definition ScrapHeap.h:67
void * baseAddress
Definition ScrapHeap.h:60
std::size_t minCommit
Definition ScrapHeap.h:64
void * commitEnd
Definition ScrapHeap.h:62
void GetMemoryStats(MemoryStats *) override
Definition ScrapHeap.h:48
void * endAddress
Definition ScrapHeap.h:61
FreeBlock * smallBlocks[6]
Definition ScrapHeap.h:57
void DeallocateAlignImpl(void *&a_block) override
Definition ScrapHeap.h:51
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::ID RTTI_ScrapHeap(static_cast< std::uint64_t >(690278))
constexpr std::array< REL::ID, 1 > VTABLE_ScrapHeap
Definition Offsets_VTABLE.h:12626
Definition IMemoryStoreBase.h:6
Definition ScrapHeap.h:16
Block * prev
Definition ScrapHeap.h:20
std::size_t sizeFlags
Definition ScrapHeap.h:19
Definition ScrapHeap.h:25
FreeBlock * right
Definition ScrapHeap.h:29
FreeBlock * left
Definition ScrapHeap.h:28
Definition ScrapHeap.h:34
FreeTreeNode * leftNode
Definition ScrapHeap.h:38
std::size_t parentAndBlack
Definition ScrapHeap.h:40
FreeTreeNode * rightNode
Definition ScrapHeap.h:39
FreeTreeNode ** root
Definition ScrapHeap.h:37