diff options
Diffstat (limited to 'zencore/iobuffer.cpp')
| -rw-r--r-- | zencore/iobuffer.cpp | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/zencore/iobuffer.cpp b/zencore/iobuffer.cpp index a730a316f..244425761 100644 --- a/zencore/iobuffer.cpp +++ b/zencore/iobuffer.cpp @@ -14,6 +14,10 @@ #include <memory.h> #include <system_error> +#if ZEN_USE_MIMALLOC +# include <mimalloc.h> +#endif + #if ZEN_PLATFORM_WINDOWS # include <atlfile.h> #else @@ -36,26 +40,41 @@ IoBufferCore::AllocateBuffer(size_t InSize, size_t Alignment) m_Flags |= kLowLevelAlloc; return VirtualAlloc(nullptr, InSize, MEM_COMMIT, PAGE_READWRITE); } - else #endif // ZEN_PLATFORM_WINDOWS - { - return Memory::Alloc(InSize, Alignment); - } + +#if ZEN_USE_MIMALLOC && 0 + void* Ptr = mi_aligned_alloc(Alignment, RoundUp(InSize, Alignment)); +#else + void* Ptr = Memory::Alloc(InSize, Alignment); +#endif + + ZEN_ASSERT(Ptr); + + return Ptr; } void IoBufferCore::FreeBuffer() { + if (!m_DataPtr) + { + return; + } + #if ZEN_PLATFORM_WINDOWS if (m_Flags & kLowLevelAlloc) { VirtualFree(const_cast<void*>(m_DataPtr), 0, MEM_DECOMMIT); + + return; } - else #endif // ZEN_PLATFORM_WINDOWS - { - return Memory::Free(const_cast<void*>(m_DataPtr)); - } + +#if ZEN_USE_MIMALLOC && 0 + return mi_free(const_cast<void*>(m_DataPtr)); +#else + return Memory::Free(const_cast<void*>(m_DataPtr)); +#endif } ////////////////////////////////////////////////////////////////////////// @@ -436,7 +455,7 @@ IoBufferBuilder::MakeFromTemporaryFile(const path_char_t* FileName) Handle = DataFile.Detach(); #else - int Fd = open(FileName, O_RDONLY); + int Fd = open(FileName, O_RDONLY); if (Fd < 0) { return {}; |