lokinet/llarp/mem_jemalloc.cpp

20 lines
376 B
C++
Raw Normal View History

2017-10-03 19:14:46 +00:00
#include <jemalloc/jemalloc.h>
2018-01-29 14:27:24 +00:00
#include <llarp/mem.h>
2017-10-03 19:14:46 +00:00
2018-01-29 14:27:24 +00:00
namespace llarp {
static void *jem_malloc(size_t sz, size_t align) {
return mallocx(sz, MALLOCX_ALIGN(align));
}
2017-10-03 19:14:46 +00:00
2018-01-29 14:27:24 +00:00
static void jem_free(void *ptr) {
2018-02-01 13:21:00 +00:00
if (ptr) free(ptr);
2017-10-03 19:14:46 +00:00
}
2018-02-01 13:21:00 +00:00
} // namespace llarp
2017-10-03 19:14:46 +00:00
extern "C" {
2018-01-29 14:27:24 +00:00
void llarp_mem_jemalloc() {
llarp_g_mem.alloc = llarp::jem_malloc;
llarp_g_mem.free = llarp::jem_free;
}
2017-10-03 19:14:46 +00:00
}