Former-commit-id: d06a447e934ee66f3f5c399fdd58f2bc95260544 [formerly 18a9328df6edb35b500a57184a8c5155e0e8f6ed] [formerly ef18cf674c43bc0e5cd0f54f50897f184b74d327 [formerly 474225aa4a4843398bfdc5e9d6c9f3db88573170]] Former-commit-id: 3d5905c69b5fd68c585cecf5191bcffe1d3557f9 [formerly 4a1183e5d7a59d8efe05091b282b406c1c4049e3] Former-commit-id: 8755e653ff0730ec687db80117405f33a4b2e430
59 lines
1.2 KiB
C++
59 lines
1.2 KiB
C++
// Copyright (C) 2015 Jérôme Leclercq
|
|
// This file is part of the "Nazara Engine - Core module"
|
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
|
|
#pragma once
|
|
|
|
#ifndef NAZARA_MEMORYHELPER_HPP
|
|
#define NAZARA_MEMORYHELPER_HPP
|
|
|
|
#if defined(NAZARA_COMPILER_MSVC) || defined(NAZARA_COMPILER_MINGW)
|
|
|
|
#include <malloc.h>
|
|
|
|
#define NAZARA_ALLOCA(size) _alloca(size)
|
|
#define NAZARA_ALLOCA_SUPPORT
|
|
|
|
#elif defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL)
|
|
#include <alloca.h>
|
|
|
|
#define NAZARA_ALLOCA(size) alloca(size)
|
|
#define NAZARA_ALLOCA_SUPPORT
|
|
|
|
#endif
|
|
|
|
#ifdef NAZARA_ALLOCA_SUPPORT
|
|
#define NazaraStackAllocation(size) Nz::StackAllocation(NAZARA_ALLOCA(size))
|
|
#else
|
|
#define NazaraStackAllocation(size) Nz::StackAllocation(Nz::OperatorNew(size))
|
|
#endif
|
|
|
|
#include <cstddef>
|
|
|
|
namespace Nz
|
|
{
|
|
void OperatorDelete(void* ptr);
|
|
void* OperatorNew(std::size_t size);
|
|
|
|
template<typename T, typename... Args>
|
|
T* PlacementNew(T* ptr, Args&&... args);
|
|
|
|
class StackAllocation
|
|
{
|
|
public:
|
|
explicit StackAllocation(void* stackMemory);
|
|
~StackAllocation();
|
|
|
|
void* GetPtr();
|
|
|
|
operator void*();
|
|
|
|
private:
|
|
void* m_ptr;
|
|
};
|
|
}
|
|
|
|
#include <Nazara/Core/MemoryHelper.inl>
|
|
|
|
#endif // NAZARA_MEMORYHELPER_HPP
|