2018-05-22 15:54:19 +00:00
|
|
|
#define NO_JEMALLOC
|
2018-01-25 16:24:33 +00:00
|
|
|
#include <llarp/mem.h>
|
2018-05-22 15:54:19 +00:00
|
|
|
#include <cstdlib>
|
2018-04-04 16:10:27 +00:00
|
|
|
#include <cstring>
|
2017-10-03 19:14:46 +00:00
|
|
|
|
2018-06-17 15:26:00 +00:00
|
|
|
struct llarp_alloc
|
|
|
|
{
|
|
|
|
void *(*alloc)(struct llarp_alloc *mem, size_t sz, size_t align);
|
|
|
|
void (*free)(struct llarp_alloc *mem, void *ptr);
|
2018-05-31 13:06:28 +00:00
|
|
|
};
|
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
void *
|
|
|
|
std_malloc(struct llarp_alloc *mem, size_t sz, size_t align)
|
|
|
|
{
|
|
|
|
(void)mem;
|
|
|
|
(void)align;
|
|
|
|
void *ptr = malloc(sz);
|
|
|
|
if(ptr)
|
|
|
|
{
|
|
|
|
std::memset(ptr, 0, sz);
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
abort();
|
2018-04-04 16:10:27 +00:00
|
|
|
}
|
2017-10-03 19:14:46 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
std_free(struct llarp_alloc *mem, void *ptr)
|
|
|
|
{
|
|
|
|
(void)mem;
|
|
|
|
if(ptr)
|
|
|
|
free(ptr);
|
|
|
|
}
|
2017-10-03 19:14:46 +00:00
|
|
|
|
2018-02-01 13:21:00 +00:00
|
|
|
} // namespace llarp
|
2018-01-29 14:27:24 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_mem_stdlib(struct llarp_alloc *mem)
|
|
|
|
{
|
2018-05-16 18:13:18 +00:00
|
|
|
mem->alloc = llarp::std_malloc;
|
2018-05-22 15:54:19 +00:00
|
|
|
mem->free = llarp::std_free;
|
2018-01-29 14:27:24 +00:00
|
|
|
}
|