From 2c682f19a66ee3182ed525f4789cc188ad536399 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Wed, 31 Aug 2022 13:34:13 +0100 Subject: [PATCH] Add untracked linear allocator emplace/allocate functions Useful for cases where allocations are guaranteed to be unused by the time `Reset()` is called and calling `Free()` would be difficult or add extra performance cost due to how the allocation is used. --- .../main/cpp/skyline/common/linear_allocator.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/cpp/skyline/common/linear_allocator.h b/app/src/main/cpp/skyline/common/linear_allocator.h index 719321de..56ec7929 100644 --- a/app/src/main/cpp/skyline/common/linear_allocator.h +++ b/app/src/main/cpp/skyline/common/linear_allocator.h @@ -29,7 +29,7 @@ namespace skyline { /** * @brief Allocates a contiguous chunk of memory of size `size` aligned to the maximum possible required alignment */ - u8 *Allocate(size_t unalignedSize) { + u8 *Allocate(size_t unalignedSize, bool track = true) { // Align the size to the maximum required alignment for standard types size_t size{util::AlignUp(unalignedSize, alignof(std::max_align_t))}; @@ -51,11 +51,22 @@ namespace skyline { chunkRemainingBytes -= size; ptr += size; - allocCount++; + if (track) + allocCount++; return allocatedPtr; } + template + T *AllocateUntracked() { + return reinterpret_cast(Allocate(sizeof(T), false)); + } + + template + T *EmplaceUntracked(Args &&... args) { + return std::construct_at(AllocateUntracked(), std::forward(args)...); + } + /** * @brief Decreases allocation count, should be called an equal number of times to `Allocate` */