mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Fix runtime of SPLIT_SHARED_LIBRARIES build
This commit is contained in:
parent
c8469ab4ba
commit
614ec98a42
43
dbms/src/Common/MiAllocator.cpp
Normal file
43
dbms/src/Common/MiAllocator.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include <Common/config.h>
|
||||
|
||||
#if USE_MIMALLOC
|
||||
|
||||
#include "MiAllocator.h"
|
||||
#include <mimalloc.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
void * MiAllocator::alloc(size_t size, size_t alignment)
|
||||
{
|
||||
if (alignment == 0)
|
||||
return mi_malloc(size);
|
||||
else
|
||||
return mi_malloc_aligned(size, alignment);
|
||||
}
|
||||
|
||||
void MiAllocator::free(void * buf, size_t)
|
||||
{
|
||||
mi_free(buf);
|
||||
}
|
||||
|
||||
void * MiAllocator::realloc(void * old_ptr, size_t, size_t new_size, size_t alignment)
|
||||
{
|
||||
if (old_ptr == nullptr)
|
||||
return alloc(new_size, alignment);
|
||||
|
||||
if (new_size == 0)
|
||||
{
|
||||
mi_free(old_ptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (alignment == 0)
|
||||
return mi_realloc(old_ptr, alignment);
|
||||
|
||||
return mi_realloc_aligned(old_ptr, new_size, alignment);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -6,7 +6,6 @@
|
||||
#error "do not include this file until USE_MIMALLOC is set to 1"
|
||||
#endif
|
||||
|
||||
#include <mimalloc.h>
|
||||
#include <cstddef>
|
||||
|
||||
namespace DB
|
||||
@ -19,37 +18,11 @@ namespace DB
|
||||
*/
|
||||
struct MiAllocator
|
||||
{
|
||||
static void * alloc(size_t size, size_t alignment = 0);
|
||||
|
||||
static void * alloc(size_t size, size_t alignment = 0)
|
||||
{
|
||||
if (alignment == 0)
|
||||
return mi_malloc(size);
|
||||
else
|
||||
return mi_malloc_aligned(size, alignment);
|
||||
}
|
||||
|
||||
static void free(void * buf, size_t)
|
||||
{
|
||||
mi_free(buf);
|
||||
}
|
||||
|
||||
static void * realloc(void * old_ptr, size_t, size_t new_size, size_t alignment = 0)
|
||||
{
|
||||
if (old_ptr == nullptr)
|
||||
return alloc(new_size, alignment);
|
||||
|
||||
if (new_size == 0)
|
||||
{
|
||||
mi_free(old_ptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (alignment == 0)
|
||||
return mi_realloc(old_ptr, alignment);
|
||||
|
||||
return mi_realloc_aligned(old_ptr, new_size, alignment);
|
||||
}
|
||||
static void free(void * buf, size_t);
|
||||
|
||||
static void * realloc(void * old_ptr, size_t, size_t new_size, size_t alignment = 0);
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user