// Copyright Epic Games, Inc. All Rights Reserved. #include #include #include #include #include #include #include #if ZEN_USE_MIMALLOC ZEN_THIRD_PARTY_INCLUDES_START # include ZEN_THIRD_PARTY_INCLUDES_END #endif namespace zen { ////////////////////////////////////////////////////////////////////////// static void* AlignedAllocImpl(size_t Size, size_t Alignment) { // aligned_alloc() states that size must be a multiple of alignment. Some // platforms return null if this requirement isn't met. Size = (Size + Alignment - 1) & ~(Alignment - 1); #if ZEN_USE_MIMALLOC return mi_aligned_alloc(Alignment, Size); #elif ZEN_PLATFORM_WINDOWS return _aligned_malloc(Size, Alignment); #else return std::aligned_alloc(Alignment, Size); #endif } void AlignedFreeImpl(void* ptr) { if (ptr == nullptr) return; #if ZEN_USE_MIMALLOC return mi_free(ptr); #elif ZEN_PLATFORM_WINDOWS _aligned_free(ptr); #else std::free(ptr); #endif } ////////////////////////////////////////////////////////////////////////// void* Memory::Alloc(size_t Size, size_t Alignment) { return AlignedAllocImpl(Size, Alignment); } void Memory::Free(void* ptr) { AlignedFreeImpl(ptr); } ////////////////////////////////////////////////////////////////////////// // // Unit tests // #if ZEN_WITH_TESTS TEST_CASE("MemoryView") { { uint8_t Array1[16] = {}; MemoryView View1 = MakeMemoryView(Array1); CHECK(View1.GetSize() == 16); } { uint32_t Array2[16] = {}; MemoryView View2 = MakeMemoryView(Array2); CHECK(View2.GetSize() == 64); } CHECK(MakeMemoryView({1.0f, 1.2f}).GetSize() == 8); } void memory_forcelink() { } #endif } // namespace zen