Compare commits

..

No commits in common. "f62574f5880e7f8166522125f17d1d2be05d4b86" and "ecba496f12508408b20ec50401832e85dfab71d0" have entirely different histories.

2 changed files with 4 additions and 26 deletions

11
.gitignore vendored
View File

@ -49,14 +49,3 @@ appimage-build/
# libs # libs
/libs/ /libs/
/vcpkg_installed/ /vcpkg_installed/
CMakeCache.txt
cmake_install.cmake
CMakeFiles/
Makefile
compile_commands.json
VoxelEngine
libVoxelEngineSrc.a
vctest
.vctest/settings.toml

View File

@ -4,12 +4,9 @@
#include <mutex> #include <mutex>
#include <vector> #include <vector>
#include <queue> #include <queue>
#include <new>
#if defined(_WIN32) #if defined(_WIN32)
#include <malloc.h> #include <malloc.h>
#else
#include <cstdlib>
#endif #endif
namespace util { namespace util {
@ -53,21 +50,13 @@ namespace util {
std::mutex mutex; std::mutex mutex;
void allocateNew() { void allocateNew() {
// Use posix_memalign on POSIX systems as aligned_alloc has stricter requirements std::unique_ptr<void, AlignedDeleter> ptr(
constexpr size_t alignment = alignof(T) < sizeof(void*) ? sizeof(void*) : alignof(T);
constexpr size_t size = sizeof(T);
void* rawPtr = nullptr;
#if defined(_WIN32) #if defined(_WIN32)
rawPtr = _aligned_malloc(size, alignment); _aligned_malloc(sizeof(T), alignof(T))
#else #else
if (posix_memalign(&rawPtr, alignment, size) != 0) { std::aligned_alloc(alignof(T), sizeof(T))
rawPtr = nullptr;
}
#endif #endif
if (rawPtr == nullptr) { );
throw std::bad_alloc();
}
std::unique_ptr<void, AlignedDeleter> ptr(rawPtr);
freeObjects.push(ptr.get()); freeObjects.push(ptr.get());
objects.push_back(std::move(ptr)); objects.push_back(std::move(ptr));
} }