139 lines
4.0 KiB
C++
139 lines
4.0 KiB
C++
// =====================================================================================================================
|
|
// fennec, a free and open source game engine
|
|
// Copyright (C) 2025 Medusa Slockbower
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//2
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
// =====================================================================================================================
|
|
|
|
///
|
|
/// \file new.h
|
|
/// \brief This header contains functions related to analyzing, modifying or copying buffers interpreted as bytes
|
|
///
|
|
///
|
|
/// \details
|
|
/// \author Medusa Slockbower
|
|
///
|
|
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
|
///
|
|
///
|
|
|
|
|
|
#ifndef FENNEC_MEMORY_NEW_H
|
|
#define FENNEC_MEMORY_NEW_H
|
|
|
|
#include <fennec/lang/types.h>
|
|
#include <fennec/lang/utility.h>
|
|
|
|
namespace fennec
|
|
{
|
|
|
|
///
|
|
/// \brief Alignment class to handle conflicting definitions
|
|
enum class align_t : size_t;
|
|
|
|
///
|
|
/// \brief Type to handle explicit nothrow definitions
|
|
struct nothrow_t
|
|
{
|
|
explicit nothrow_t() noexcept { }
|
|
};
|
|
|
|
///
|
|
/// \returns the page size for the current environment
|
|
size_t pagesize();
|
|
|
|
template<typename TypeT> void construct(TypeT* ptr) {
|
|
ptr->TypeT();
|
|
}
|
|
|
|
template<typename TypeT> void construct(TypeT* ptr, const TypeT& val) {
|
|
ptr->TypeT(val);
|
|
}
|
|
|
|
template<typename TypeT> void construct(TypeT* ptr, TypeT&& val) {
|
|
ptr->TypeT(fennec::forward<TypeT>(val));
|
|
}
|
|
|
|
template<typename TypeT, typename...ArgsT> void construct(TypeT* ptr, ArgsT...args) {
|
|
ptr->TypeT(fennec::forward<TypeT>(args)...);
|
|
}
|
|
|
|
template<typename TypeT> void destruct(TypeT* ptr) {
|
|
ptr->~TypeT();
|
|
}
|
|
|
|
}
|
|
|
|
void* operator new (fennec::size_t size);
|
|
void* operator new[](fennec::size_t size);
|
|
void* operator new (fennec::size_t size, const fennec::nothrow_t&);
|
|
void* operator new[](fennec::size_t size, const fennec::nothrow_t&);
|
|
void* operator new (fennec::size_t size, fennec::align_t align);
|
|
void* operator new[](fennec::size_t size, fennec::align_t align);
|
|
void* operator new (fennec::size_t size, fennec::align_t align, const fennec::nothrow_t&);
|
|
void* operator new[](fennec::size_t size, fennec::align_t align, const fennec::nothrow_t&);
|
|
|
|
|
|
void operator delete (void* ptr) noexcept;
|
|
void operator delete[](void* ptr) noexcept;
|
|
void operator delete (void* ptr, fennec::size_t) noexcept;
|
|
void operator delete[](void* ptr, fennec::size_t) noexcept;
|
|
void operator delete (void* ptr, const fennec::nothrow_t&) noexcept;
|
|
void operator delete[](void* ptr, const fennec::nothrow_t&) noexcept;
|
|
void operator delete (void* ptr, fennec::size_t, const fennec::nothrow_t&) noexcept;
|
|
void operator delete[](void* ptr, fennec::size_t, const fennec::nothrow_t&) noexcept;
|
|
|
|
void operator delete (void* ptr, fennec::align_t) noexcept;
|
|
void operator delete[](void* ptr, fennec::align_t) noexcept;
|
|
void operator delete (void* ptr, fennec::size_t, fennec::align_t) noexcept;
|
|
void operator delete[](void* ptr, fennec::size_t, fennec::align_t) noexcept;
|
|
void operator delete (void* ptr, fennec::align_t, const fennec::nothrow_t&) noexcept;
|
|
void operator delete[](void* ptr, fennec::align_t, const fennec::nothrow_t&) noexcept;
|
|
|
|
|
|
// Platform specific code
|
|
#ifdef _WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#include <windows.h>
|
|
|
|
namespace fennec
|
|
{
|
|
|
|
inline size_T pagesize() {
|
|
SYSTEM_INFO sysInfo;
|
|
GetSystemInfo(&sysInfo);
|
|
return sysInfo.dwPageSize;
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
namespace fennec
|
|
{
|
|
|
|
inline size_t pagesize() {
|
|
return sysconf(_SC_PAGESIZE);
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
#endif // FENNEC_MEMORY_NEW_H
|