Core: Replace StackAllocation by StackArray
This will cleanup alloca usage a little bit
This commit is contained in:
@@ -23,12 +23,15 @@
|
||||
#endif
|
||||
|
||||
#ifdef NAZARA_ALLOCA_SUPPORT
|
||||
#define NazaraStackAllocation(size) Nz::StackAllocation(NAZARA_ALLOCA(size))
|
||||
#define NazaraStackAllocation(T, size) Nz::StackArray<T>(static_cast<T*>(NAZARA_ALLOCA((size) * sizeof(T))), size)
|
||||
#define NazaraStackAllocationNoInit(T, size) Nz::StackArray<T>(static_cast<T*>(NAZARA_ALLOCA((size) * sizeof(T))), size, Nz::NoInitTag())
|
||||
#else
|
||||
#define NazaraStackAllocation(size) Nz::StackAllocation(Nz::OperatorNew(size))
|
||||
#define NazaraStackAllocation(T, size) Nz::StackArray<T>(static_cast<T*>(Nz::OperatorNew((size) * sizeof(T))), size)
|
||||
#define NazaraStackAllocationNoInit(T, size) Nz::StackArray<T>(static_cast<T*>(Nz::OperatorNew((size) * sizeof(T))), size, Nz::NoInitTag())
|
||||
#endif
|
||||
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -41,19 +44,70 @@ namespace Nz
|
||||
template<typename T>
|
||||
void PlacementDestroy(T* ptr);
|
||||
|
||||
class StackAllocation
|
||||
struct NoInitTag {};
|
||||
|
||||
template<typename T>
|
||||
class StackArray
|
||||
{
|
||||
public:
|
||||
explicit StackAllocation(void* stackMemory);
|
||||
~StackAllocation();
|
||||
using value_type = T;
|
||||
using const_iterator = const value_type*;
|
||||
using const_pointer = const value_type*;
|
||||
using const_reference = const value_type&;
|
||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using iterator = value_type*;
|
||||
using pointer = value_type*;
|
||||
using reference = value_type&;
|
||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||
using size_type = std::size_t;
|
||||
|
||||
void* GetPtr();
|
||||
StackArray(T* stackMemory, std::size_t size);
|
||||
StackArray(T* stackMemory, std::size_t size, NoInitTag);
|
||||
~StackArray();
|
||||
|
||||
operator void*();
|
||||
reference back();
|
||||
const_reference back() const;
|
||||
|
||||
iterator begin() noexcept;
|
||||
const_iterator begin() const noexcept;
|
||||
|
||||
const_iterator cbegin() const noexcept;
|
||||
const_iterator cend() const noexcept;
|
||||
const_iterator crbegin() const noexcept;
|
||||
const_iterator crend() const noexcept;
|
||||
|
||||
T* data() noexcept;
|
||||
const T* data() const noexcept;
|
||||
|
||||
bool empty() const noexcept;
|
||||
|
||||
iterator end() noexcept;
|
||||
const_iterator end() const noexcept;
|
||||
|
||||
void fill(const T& value);
|
||||
|
||||
reference front() noexcept;
|
||||
const_reference front() const noexcept;
|
||||
|
||||
size_type max_size() const noexcept;
|
||||
|
||||
reverse_iterator rbegin() noexcept;
|
||||
const_reverse_iterator rbegin() const noexcept;
|
||||
|
||||
reverse_iterator rend() noexcept;
|
||||
const_reverse_iterator rend() const noexcept;
|
||||
|
||||
size_type size() const noexcept;
|
||||
|
||||
reference operator[](size_type pos);
|
||||
const_reference operator[](size_type pos) const;
|
||||
|
||||
private:
|
||||
void* m_ptr;
|
||||
std::size_t m_size;
|
||||
T* m_ptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include <Nazara/Core/MemoryHelper.inl>
|
||||
|
||||
Reference in New Issue
Block a user