Core/MemoryHelper: Add portable stack allocation
Former-commit-id: f1c38cd50d028ab9c3b7868178d457a3bde30158 [formerly 09f688b51171507d684db1a6e865f65202295ca3] [formerly da2fe586a5e71591f7869a24b0178d3b3554de67 [formerly 99d022f578a47294795819cddc85c1c41a08a943]] Former-commit-id: d92a834a6538f1a8d74bbaebb898d9abf48135ca [formerly 6db2b81497d7252583dda33c4a1bf03a77c8ba43] Former-commit-id: fa05a671eed209de23671b8d396217f0851011d1
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#define NAZARA_DEBUG_NEWREDEFINITION_DISABLE_REDEFINITION
|
||||
#endif
|
||||
|
||||
#include <Nazara/Core/MemoryHelper.hpp>
|
||||
#include <Nazara/Core/MemoryManager.hpp>
|
||||
#include <new>
|
||||
#include <utility>
|
||||
@@ -62,6 +63,51 @@ namespace Nz
|
||||
{
|
||||
return new (ptr) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::StackAllocation
|
||||
* \brief Core class that represents a stack allocation
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Constructs a StackAllocation object with a pointer to a memory allocated with NAZARA_ALLOCA or OperatorNew is alloca is not supported
|
||||
*
|
||||
* \param ptr Pointer to raw memory
|
||||
*/
|
||||
inline StackAllocation::StackAllocation(void* stackMemory) :
|
||||
m_ptr(stackMemory)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destructs the object and release memory if necessary
|
||||
*/
|
||||
inline StackAllocation::~StackAllocation()
|
||||
{
|
||||
#ifndef NAZARA_ALLOCA_SUPPORT
|
||||
OperatorDelete(m_ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Access the internal pointer
|
||||
* \return internal memory pointer
|
||||
*/
|
||||
inline void* StackAllocation::GetPtr()
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Access the internal pointer
|
||||
* \return internal memory pointer
|
||||
*/
|
||||
inline StackAllocation::operator void*()
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
Reference in New Issue
Block a user