Added memory helpers
This will protect some memory-related code from new redefinition Former-commit-id: 337e69e70acd0bf8dbc3ba1657c6bb0bddfd5df4
This commit is contained in:
45
include/Nazara/Core/MemoryHelper.inl
Normal file
45
include/Nazara/Core/MemoryHelper.inl
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2014 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
|
||||
|
||||
// Je ne suis pas fier des cinq lignes qui suivent mais difficile de faire autrement pour le moment...
|
||||
#ifdef NAZARA_DEBUG_NEWREDEFINITION_DISABLE_REDEFINITION
|
||||
#define NAZARA_DEBUG_NEWREDEFINITION_DISABLE_REDEFINITION_DEFINED
|
||||
#else
|
||||
#define NAZARA_DEBUG_NEWREDEFINITION_DISABLE_REDEFINITION
|
||||
#endif
|
||||
|
||||
#include <Nazara/Core/MemoryManager.hpp>
|
||||
#include <new>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
inline void NzOperatorDelete(void* ptr)
|
||||
{
|
||||
#if NAZARA_CORE_MANAGE_MEMORY
|
||||
NzMemoryManager::Free(ptr);
|
||||
#else
|
||||
operator delete(ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void* NzOperatorNew(std::size_t size)
|
||||
{
|
||||
#if NAZARA_CORE_MANAGE_MEMORY
|
||||
return NzMemoryManager::Allocate(size);
|
||||
#else
|
||||
return operator new(size);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
T* NzPlacementNew(void* ptr, Args... args)
|
||||
{
|
||||
return new (ptr) T(args...);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
// Si c'est nous qui avons défini la constante, alors il nous faut l'enlever (Pour éviter que le moteur entier n'en souffre)
|
||||
#ifndef NAZARA_DEBUG_NEWREDEFINITION_DISABLE_REDEFINITION_DEFINED
|
||||
#undef NAZARA_DEBUG_NEWREDEFINITION_DISABLE_REDEFINITION
|
||||
#endif
|
||||
Reference in New Issue
Block a user