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.
This commit is contained in:
Billy Laws 2022-08-31 13:34:13 +01:00
parent 6359852652
commit 2c682f19a6

View File

@ -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<typename T>
T *AllocateUntracked() {
return reinterpret_cast<T *>(Allocate(sizeof(T), false));
}
template<typename T, class... Args>
T *EmplaceUntracked(Args &&... args) {
return std::construct_at(AllocateUntracked<T>(), std::forward<Args>(args)...);
}
/**
* @brief Decreases allocation count, should be called an equal number of times to `Allocate`
*/