mirror of
https://github.com/microsoft/mimalloc.git
synced 2024-12-26 21:04:27 +08:00
merge stl and main header
This commit is contained in:
parent
1b2b7404f7
commit
526bee6843
@ -187,7 +187,6 @@ install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION ${mi_install_dir})
|
||||
install(FILES include/mimalloc.h DESTINATION ${mi_install_dir}/include)
|
||||
install(FILES include/mimalloc-override.h DESTINATION ${mi_install_dir}/include)
|
||||
install(FILES include/mimalloc-new-delete.h DESTINATION ${mi_install_dir}/include)
|
||||
install(FILES include/mimalloc-stl-allocator.h DESTINATION ${mi_install_dir}/include)
|
||||
install(FILES cmake/mimalloc-config.cmake DESTINATION ${mi_install_dir}/cmake)
|
||||
install(FILES cmake/mimalloc-config-version.cmake DESTINATION ${mi_install_dir}/cmake)
|
||||
install(EXPORT mimalloc DESTINATION ${mi_install_dir}/cmake)
|
||||
|
@ -214,7 +214,6 @@
|
||||
<ClInclude Include="..\..\include\mimalloc-atomic.h" />
|
||||
<ClInclude Include="..\..\include\mimalloc-new-delete.h" />
|
||||
<ClInclude Include="..\..\include\mimalloc-override.h" />
|
||||
<ClInclude Include="..\..\include\mimalloc-stl-allocator.h" />
|
||||
<ClInclude Include="..\..\include\mimalloc-types.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -239,7 +239,6 @@
|
||||
<ClInclude Include="$(ProjectDir)..\..\include\mimalloc-override.h" />
|
||||
<ClInclude Include="$(ProjectDir)..\..\include\mimalloc-types.h" />
|
||||
<ClInclude Include="..\..\include\mimalloc-new-delete.h" />
|
||||
<ClInclude Include="..\..\include\mimalloc-stl-allocator.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -214,7 +214,6 @@
|
||||
<ClInclude Include="..\..\include\mimalloc-atomic.h" />
|
||||
<ClInclude Include="..\..\include\mimalloc-new-delete.h" />
|
||||
<ClInclude Include="..\..\include\mimalloc-override.h" />
|
||||
<ClInclude Include="..\..\include\mimalloc-stl-allocator.h" />
|
||||
<ClInclude Include="..\..\include\mimalloc-types.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -239,7 +239,6 @@
|
||||
<ClInclude Include="$(ProjectDir)..\..\include\mimalloc-override.h" />
|
||||
<ClInclude Include="$(ProjectDir)..\..\include\mimalloc-types.h" />
|
||||
<ClInclude Include="..\..\include\mimalloc-new-delete.h" />
|
||||
<ClInclude Include="..\..\include\mimalloc-stl-allocator.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -1,43 +0,0 @@
|
||||
#pragma once
|
||||
#ifndef MIMALLOC_STL_ALLOCATOR_H
|
||||
#define MIMALLOC_STL_ALLOCATOR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* ----------------------------------------------------------------------------
|
||||
This header can be used to hook mimalloc into STL containers in place of
|
||||
std::allocator.
|
||||
-----------------------------------------------------------------------------*/
|
||||
#include <type_traits> // true_type
|
||||
|
||||
#pragma warning(disable: 4100)
|
||||
|
||||
template <class T>
|
||||
struct mi_stl_allocator {
|
||||
typedef T value_type;
|
||||
|
||||
using propagate_on_container_copy_assignment = std::true_type;
|
||||
using propagate_on_container_move_assignment = std::true_type;
|
||||
using propagate_on_container_swap = std::true_type;
|
||||
using is_always_equal = std::true_type;
|
||||
|
||||
mi_stl_allocator() noexcept {}
|
||||
mi_stl_allocator(const mi_stl_allocator& other) noexcept {}
|
||||
template <class U>
|
||||
mi_stl_allocator(const mi_stl_allocator<U>& other) noexcept {}
|
||||
|
||||
T* allocate(size_t n, const void* hint = 0) {
|
||||
return (T*)mi_mallocn(n, sizeof(T));
|
||||
}
|
||||
|
||||
void deallocate(T* p, size_t n) {
|
||||
mi_free(p);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T1, class T2>
|
||||
bool operator==(const mi_stl_allocator<T1>& lhs, const mi_stl_allocator<T2>& rhs) noexcept { return true; }
|
||||
template <class T1, class T2>
|
||||
bool operator!=(const mi_stl_allocator<T1>& lhs, const mi_stl_allocator<T2>& rhs) noexcept { return false; }
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif // MIMALLOC_STL_ALLOCATOR_H
|
@ -73,7 +73,7 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||
#include <stdbool.h> // bool
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <mimalloc-stl-allocator.h>
|
||||
#include <type_traits> // true_type
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -328,5 +328,41 @@ mi_decl_export void* mi_new_aligned_nothrow(size_t n, size_t alignment) mi_attr_
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
// ------------------------------------------------------
|
||||
// STL allocator - an extension to hook mimalloc into STL
|
||||
// containers in place of std::allocator.
|
||||
// ------------------------------------------------------
|
||||
|
||||
#pragma warning(disable: 4100)
|
||||
template <class T>
|
||||
struct mi_stl_allocator {
|
||||
typedef T value_type;
|
||||
|
||||
using propagate_on_container_copy_assignment = std::true_type;
|
||||
using propagate_on_container_move_assignment = std::true_type;
|
||||
using propagate_on_container_swap = std::true_type;
|
||||
using is_always_equal = std::true_type;
|
||||
|
||||
mi_stl_allocator() noexcept {}
|
||||
mi_stl_allocator(const mi_stl_allocator& other) noexcept {}
|
||||
template <class U>
|
||||
mi_stl_allocator(const mi_stl_allocator<U>& other) noexcept {}
|
||||
|
||||
T* allocate(size_t n, const void* hint = 0) {
|
||||
return (T*)mi_mallocn(n, sizeof(T));
|
||||
}
|
||||
|
||||
void deallocate(T* p, size_t n) {
|
||||
mi_free(p);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T1, class T2>
|
||||
bool operator==(const mi_stl_allocator<T1>& lhs, const mi_stl_allocator<T2>& rhs) noexcept { return true; }
|
||||
template <class T1, class T2>
|
||||
bool operator!=(const mi_stl_allocator<T1>& lhs, const mi_stl_allocator<T2>& rhs) noexcept { return false; }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -32,7 +32,6 @@ we therefore test the API over various inputs. Please add more tests :-)
|
||||
|
||||
#include "mimalloc.h"
|
||||
#include "mimalloc-internal.h"
|
||||
#include "mimalloc-stl-allocator.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Test macros: CHECK(name,predicate) and CHECK_BODY(name,body)
|
||||
|
Loading…
x
Reference in New Issue
Block a user