Added memory helpers

This will protect some memory-related code from new redefinition


Former-commit-id: 337e69e70acd0bf8dbc3ba1657c6bb0bddfd5df4
This commit is contained in:
Lynix
2014-07-22 17:26:31 +02:00
parent fba2e5ae01
commit e6dea541a7
7 changed files with 79 additions and 28 deletions

View 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