2019-09-16 05:19:00 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
2021-04-24 19:35:11 +03:00
|
|
|
Copyright (c) 2018-2020 Microsoft Research, Daan Leijen
|
2019-09-16 05:19:00 +03:00
|
|
|
This is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the MIT license. A copy of the license can be found in the file
|
|
|
|
"LICENSE" at the root of this distribution.
|
|
|
|
-----------------------------------------------------------------------------*/
|
|
|
|
#pragma once
|
|
|
|
#ifndef MIMALLOC_NEW_DELETE_H
|
|
|
|
#define MIMALLOC_NEW_DELETE_H
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// This header provides convenient overrides for the new and
|
|
|
|
// delete operations in C++.
|
|
|
|
//
|
|
|
|
// This header should be included in only one source file!
|
|
|
|
//
|
|
|
|
// On Windows, or when linking dynamically with mimalloc, these
|
|
|
|
// can be more performant than the standard new-delete operations.
|
|
|
|
// See <https://en.cppreference.com/w/cpp/memory/new/operator_new>
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#include <new>
|
|
|
|
#include <mimalloc.h>
|
|
|
|
|
|
|
|
void operator delete(void* p) noexcept { mi_free(p); };
|
|
|
|
void operator delete[](void* p) noexcept { mi_free(p); };
|
|
|
|
|
2022-02-22 23:29:14 +03:00
|
|
|
void operator delete (void* p, const std::nothrow_t&) noexcept { mi_free(p); }
|
|
|
|
void operator delete[](void* p, const std::nothrow_t&) noexcept { mi_free(p); }
|
|
|
|
|
2019-09-16 05:19:00 +03:00
|
|
|
void* operator new(std::size_t n) noexcept(false) { return mi_new(n); }
|
|
|
|
void* operator new[](std::size_t n) noexcept(false) { return mi_new(n); }
|
|
|
|
|
|
|
|
void* operator new (std::size_t n, const std::nothrow_t& tag) noexcept { (void)(tag); return mi_new_nothrow(n); }
|
|
|
|
void* operator new[](std::size_t n, const std::nothrow_t& tag) noexcept { (void)(tag); return mi_new_nothrow(n); }
|
|
|
|
|
|
|
|
#if (__cplusplus >= 201402L || _MSC_VER >= 1916)
|
2020-02-03 09:04:53 +03:00
|
|
|
void operator delete (void* p, std::size_t n) noexcept { mi_free_size(p,n); };
|
|
|
|
void operator delete[](void* p, std::size_t n) noexcept { mi_free_size(p,n); };
|
2019-09-16 05:19:00 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (__cplusplus > 201402L || defined(__cpp_aligned_new))
|
|
|
|
void operator delete (void* p, std::align_val_t al) noexcept { mi_free_aligned(p, static_cast<size_t>(al)); }
|
|
|
|
void operator delete[](void* p, std::align_val_t al) noexcept { mi_free_aligned(p, static_cast<size_t>(al)); }
|
|
|
|
void operator delete (void* p, std::size_t n, std::align_val_t al) noexcept { mi_free_size_aligned(p, n, static_cast<size_t>(al)); };
|
|
|
|
void operator delete[](void* p, std::size_t n, std::align_val_t al) noexcept { mi_free_size_aligned(p, n, static_cast<size_t>(al)); };
|
2022-11-02 19:50:49 +03:00
|
|
|
void operator delete (void* p, std::align_val_t al, const std::nothrow_t&) noexcept { mi_free_aligned(p, static_cast<size_t>(al)); }
|
|
|
|
void operator delete[](void* p, std::align_val_t al, const std::nothrow_t&) noexcept { mi_free_aligned(p, static_cast<size_t>(al)); }
|
2022-02-23 00:49:39 +03:00
|
|
|
|
|
|
|
void* operator new (std::size_t n, std::align_val_t al) noexcept(false) { return mi_new_aligned(n, static_cast<size_t>(al)); }
|
|
|
|
void* operator new[](std::size_t n, std::align_val_t al) noexcept(false) { return mi_new_aligned(n, static_cast<size_t>(al)); }
|
2019-09-16 05:19:00 +03:00
|
|
|
void* operator new (std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { return mi_new_aligned_nothrow(n, static_cast<size_t>(al)); }
|
|
|
|
void* operator new[](std::size_t n, std::align_val_t al, const std::nothrow_t&) noexcept { return mi_new_aligned_nothrow(n, static_cast<size_t>(al)); }
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // MIMALLOC_NEW_DELETE_H
|