// Copyright 2023 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. #pragma once #include #include #include namespace Common { /** * A ScratchBuffer is a simple heap allocated array without member initialization. * Main usage is for temporary buffers passed to threads for example */ template class ScratchBuffer { static_assert(std::is_trivial_v, "Must use a POD type"); public: ScratchBuffer(std::size_t size_) : size{size_} { buffer = std::unique_ptr(new typename std::remove_extent::type[size]); } [[nodiscard]] std::size_t Size() const noexcept { return size; } [[nodiscard]] T* Data() const noexcept { return buffer.get(); } [[nodiscard]] std::span Span(u32 index = 0) const noexcept { return std::span{buffer.get() + index, size - index}; } [[nodiscard]] std::span Span(u32 index = 0) noexcept { return std::span{buffer.get() + index, size - index}; } private: std::unique_ptr buffer; std::size_t size; }; } // namespace Common