7 namespace CompactingStore
12 class BSSmallBlockAllocator;
36 [[nodiscard]]
void*
Allocate(std::size_t a_size, std::int32_t a_alignment,
bool a_alignmentRequired)
40 return func(
this, a_size, a_alignment, a_alignmentRequired);
47 return func(
this, a_mem, a_alignmentRequired);
57 [[nodiscard]]
void*
Reallocate(
void* a_oldMem, std::size_t a_newSize, std::int32_t a_alignment,
bool a_aligned)
61 return func(
this, a_oldMem, a_newSize, a_alignment, a_aligned);
96 static_assert(
sizeof(MemoryManager) == 0x480);
98 inline void*
malloc(std::size_t a_size)
102 heap->Allocate(a_size, 0,
false) :
109 return static_cast<T*
>(
malloc(a_size));
115 return malloc<T>(
sizeof(T));
122 heap->Allocate(a_size,
static_cast<std::int32_t
>(a_alignment),
true) :
135 return aligned_alloc<T>(
alignof(T),
sizeof(T));
138 inline void*
calloc(std::size_t a_num, std::size_t a_size)
140 return malloc(a_num * a_size);
144 inline T*
calloc(std::size_t a_num, std::size_t a_size)
146 return static_cast<T*
>(
calloc(a_num, a_size));
152 return calloc<T>(a_num,
sizeof(T));
155 inline void*
realloc(
void* a_ptr, std::size_t a_newSize)
159 heap->Reallocate(a_ptr, a_newSize, 0,
false) :
164 inline T*
realloc(
void* a_ptr, std::size_t a_newSize)
166 return static_cast<T*
>(
realloc(a_ptr, a_newSize));
169 inline void*
aligned_realloc(
void* a_ptr, std::size_t a_newSize, std::size_t a_alignment)
173 heap->Reallocate(a_ptr, a_newSize,
static_cast<std::int32_t
>(a_alignment),
true) :
178 inline T*
aligned_realloc(
void* a_ptr, std::size_t a_newSize, std::size_t a_alignment)
180 return static_cast<T*
>(
aligned_realloc(a_ptr, a_newSize, a_alignment));
187 heap->Deallocate(a_ptr,
false);
195 heap->Deallocate(a_ptr,
true);
200#define TES_HEAP_REDEFINE_NEW() \
201 [[nodiscard]] inline void* operator new(std::size_t a_count) \
203 const auto mem = RE::malloc(a_count); \
207 stl::report_and_fail("out of memory"sv); \
211 [[nodiscard]] inline void* operator new[](std::size_t a_count) \
213 const auto mem = RE::malloc(a_count); \
217 stl::report_and_fail("out of memory"sv); \
221 [[nodiscard]] constexpr void* operator new(std::size_t, void* a_ptr) noexcept { return a_ptr; } \
222 [[nodiscard]] constexpr void* operator new[](std::size_t, void* a_ptr) noexcept { return a_ptr; } \
223 [[nodiscard]] constexpr void* operator new(std::size_t, std::align_val_t, void* a_ptr) noexcept { return a_ptr; } \
224 [[nodiscard]] constexpr void* operator new[](std::size_t, std::align_val_t, void* a_ptr) noexcept { return a_ptr; } \
226 inline void operator delete(void* a_ptr) { RE::free(a_ptr); } \
227 inline void operator delete[](void* a_ptr) { RE::free(a_ptr); } \
228 inline void operator delete(void* a_ptr, std::align_val_t) { RE::aligned_free(a_ptr); } \
229 inline void operator delete[](void* a_ptr, std::align_val_t) { RE::aligned_free(a_ptr); } \
230 inline void operator delete(void* a_ptr, std::size_t) { RE::free(a_ptr); } \
231 inline void operator delete[](void* a_ptr, std::size_t) { RE::free(a_ptr); } \
232 inline void operator delete(void* a_ptr, std::size_t, std::align_val_t) { RE::aligned_free(a_ptr); } \
233 inline void operator delete[](void* a_ptr, std::size_t, std::align_val_t) { RE::aligned_free(a_ptr); }
258 static_assert(!std::is_trivially_destructible_v<value_type>,
"there's no allocation overhead for trivially destructible types");
266 assert(a_pos <
size());
272 assert(a_pos <
size());
293 [[nodiscard]]
bool empty() const noexcept {
return size() == 0; }
308 const auto oldSize =
size();
309 if (oldSize == a_count) {
313 const auto newData = [=]() {
315 if constexpr (
alignof(
value_type) >
alignof(std::size_t)) {
318 bytes +=
sizeof(std::size_t);
321 const auto data = malloc<std::size_t>(bytes);
324 if constexpr (
alignof(
value_type) >
alignof(std::size_t)) {
331 if (a_count < oldSize) {
332 std::uninitialized_move_n(
data(), a_count, newData);
334 std::uninitialized_move_n(
data(), oldSize, newData);
335 std::uninitialized_default_construct_n(newData + oldSize, a_count - oldSize);
345 assert(
_data !=
nullptr);
346 if constexpr (
alignof(
value_type) >
alignof(std::size_t)) {
349 return reinterpret_cast<std::size_t*
>(
_data) - 1;
353 [[nodiscard]]
const void*
get_head() const noexcept
355 assert(
_data !=
nullptr);
356 if constexpr (
alignof(
value_type) >
alignof(std::size_t)) {
359 return reinterpret_cast<const std::size_t*
>(
_data) - 1;
Definition: BSSmallBlockAllocator.h:61
Definition: CompactingStore.h:15
Definition: IMemoryHeap.h:31
Definition: MemoryManager.h:16
std::uint16_t numHeaps
Definition: MemoryManager.h:73
BSSmallBlockAllocator * smallBlockAllocator
Definition: MemoryManager.h:82
std::uint32_t mallocBytes
Definition: MemoryManager.h:88
IMemoryHeap * defaultHeap
Definition: MemoryManager.h:94
std::uint32_t numMemoryProblemPassesRun
Definition: MemoryManager.h:92
std::uint16_t numPhysicalHeaps
Definition: MemoryManager.h:74
bool specialHeaps
Definition: MemoryManager.h:85
CompactingStore::Store * compactingStore
Definition: MemoryManager.h:83
std::uint32_t alignmentForPools
Definition: MemoryManager.h:89
void Deallocate(void *a_mem, bool a_alignmentRequired)
Definition: MemoryManager.h:43
static MemoryManager * GetSingleton()
Definition: MemoryManager.h:29
std::size_t failedAllocationSize
Definition: MemoryManager.h:91
void * Reallocate(void *a_oldMem, std::size_t a_newSize, std::int32_t a_alignment, bool a_aligned)
Definition: MemoryManager.h:57
ThreadScrapHeap * threadScrapHeap
Definition: MemoryManager.h:78
bool allowPoolUse
Definition: MemoryManager.h:86
std::uint32_t sysAllocBytes
Definition: MemoryManager.h:87
IMemoryHeap ** physicalHeaps
Definition: MemoryManager.h:79
IMemoryHeap ** heaps
Definition: MemoryManager.h:75
IMemoryHeap * bigAllocHeap
Definition: MemoryManager.h:80
ScrapHeap * GetThreadScrapHeap()
Definition: MemoryManager.h:50
std::uint32_t mainThreadMemoryProblemPassSignal
Definition: MemoryManager.h:90
IMemoryHeap * emergencyHeap
Definition: MemoryManager.h:81
std::size_t timeOfLastMemoryProblemPass
Definition: MemoryManager.h:93
void RegisterMemoryManager()
Definition: MemoryManager.h:64
IMemoryHeap * externalHavokAllocator
Definition: MemoryManager.h:84
IMemoryHeap * heapsByContext[127]
Definition: MemoryManager.h:77
bool * allowOtherContextAllocs
Definition: MemoryManager.h:76
bool initialized
Definition: MemoryManager.h:72
void * Allocate(std::size_t a_size, std::int32_t a_alignment, bool a_alignmentRequired)
Definition: MemoryManager.h:36
Definition: ScrapHeap.h:8
Definition: MemoryManager.h:240
const_iterator begin() const noexcept
Definition: MemoryManager.h:286
const_iterator end() const noexcept
Definition: MemoryManager.h:290
size_type size() const noexcept
Definition: MemoryManager.h:295
value_type & reference
Definition: MemoryManager.h:245
std::size_t size_type
Definition: MemoryManager.h:243
T value_type
Definition: MemoryManager.h:242
const_iterator cend() const noexcept
Definition: MemoryManager.h:291
pointer data() noexcept
Definition: MemoryManager.h:282
iterator begin() noexcept
Definition: MemoryManager.h:285
void clear()
Definition: MemoryManager.h:297
pointer _data
Definition: MemoryManager.h:364
iterator end() noexcept
Definition: MemoryManager.h:289
const value_type & const_reference
Definition: MemoryManager.h:246
~SimpleArray()
Definition: MemoryManager.h:256
reference back() noexcept
Definition: MemoryManager.h:279
void * get_head() noexcept
Definition: MemoryManager.h:343
value_type * iterator
Definition: MemoryManager.h:249
reference front() noexcept
Definition: MemoryManager.h:276
void resize(size_type a_count)
Definition: MemoryManager.h:306
value_type * pointer
Definition: MemoryManager.h:247
bool empty() const noexcept
Definition: MemoryManager.h:293
const value_type * const_iterator
Definition: MemoryManager.h:250
constexpr SimpleArray() noexcept=default
const_reference front() const noexcept
Definition: MemoryManager.h:277
const_reference operator[](size_type a_pos) const noexcept
Definition: MemoryManager.h:270
const_pointer data() const noexcept
Definition: MemoryManager.h:283
const_iterator cbegin() const noexcept
Definition: MemoryManager.h:287
const_reference back() const noexcept
Definition: MemoryManager.h:280
std::ptrdiff_t difference_type
Definition: MemoryManager.h:244
const void * get_head() const noexcept
Definition: MemoryManager.h:353
const value_type * const_pointer
Definition: MemoryManager.h:248
reference operator[](size_type a_pos) noexcept
Definition: MemoryManager.h:264
Definition: Relocation.h:858
constexpr REL::ID GetThreadScrapHeap(static_cast< std::uint64_t >(68088))
constexpr REL::ID Reallocate(static_cast< std::uint64_t >(68116))
constexpr REL::ID Allocate(static_cast< std::uint64_t >(68115))
constexpr REL::ID Deallocate(static_cast< std::uint64_t >(68117))
constexpr REL::ID GetSingleton(static_cast< std::uint64_t >(11141))
constexpr REL::ID RegisterMemoryManager(static_cast< std::uint64_t >(36091))
Definition: AbsorbEffect.h:6
void * realloc(void *a_ptr, std::size_t a_newSize)
Definition: MemoryManager.h:155
T * aligned_alloc()
Definition: MemoryManager.h:133
T * malloc()
Definition: MemoryManager.h:113
void * calloc(std::size_t a_num, std::size_t a_size)
Definition: MemoryManager.h:138
void * aligned_realloc(void *a_ptr, std::size_t a_newSize, std::size_t a_alignment)
Definition: MemoryManager.h:169
void free(void *a_ptr)
Definition: MemoryManager.h:183
void aligned_free(void *a_ptr)
Definition: MemoryManager.h:191
Definition: MemoryManager.h:19
ScrapHeap heap
Definition: MemoryManager.h:22
ThreadScrapHeap * next
Definition: MemoryManager.h:23
std::uint32_t owningThread
Definition: MemoryManager.h:24
std::uint32_t pad
Definition: MemoryManager.h:25