Core/MemoryHelper: Add portable stack allocation
Former-commit-id: 50b96029c53d1784f028148f1ec15ae2cf98d036 [formerly eb3398905190df3d0dc77c8a3b54bb455059e39b] [formerly bfac4638e043161208ee7cf4735a788b1427f73e [formerly 1ee0a59ab5aa407c995afd287a9aaa4307075754]] Former-commit-id: 521c4248c638e5141534cd1d223d8f563693b821 [formerly 203f6191b3b24ccb2e04d330372973dadfb81e1d] Former-commit-id: 140a5c705819055b4d27f43156b079d6142049a5
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