Fix runtime of SPLIT_SHARED_LIBRARIES build

This commit is contained in:
Danila Kutenin 2019-06-28 21:26:24 +03:00
parent c8469ab4ba
commit 614ec98a42
2 changed files with 46 additions and 30 deletions

View 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

View File

@ -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);
};
}