diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2015-04-12 11:40:08 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-04-13 08:22:59 -0300 |
commit | 8a1a9b9558d6f3e28cc97254c1bacfbc823d05e2 (patch) | |
tree | 89ef647267ef31794eeb2f297886e6bde97dcf10 /src/nvim/memory.c | |
parent | 34c48aaf123ffd8aec31b79f0b4d16d9a63fe59b (diff) | |
download | rneovim-8a1a9b9558d6f3e28cc97254c1bacfbc823d05e2.tar.gz rneovim-8a1a9b9558d6f3e28cc97254c1bacfbc823d05e2.tar.bz2 rneovim-8a1a9b9558d6f3e28cc97254c1bacfbc823d05e2.zip |
deps: Add jemalloc as an optional dependency
Jemalloc will be used if the cmake option `USE_JEMALLOC` is enabled(which is the
default). To avoid trouble with clang's ASAN, it is disabled by default if the
`SANITIZE` option is enabled.
Since jemalloc has thread cache for small objects, it fills the gap created by
removing klib memory pools.
The `xstrdup` funciton(memory.c) had to be reimplemented on top of `xmalloc` to
make it work with a custom allocator.
Diffstat (limited to 'src/nvim/memory.c')
-rw-r--r-- | src/nvim/memory.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 35409aef49..2d4259a238 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -18,6 +18,14 @@ # include "memory.c.generated.h" #endif +#if defined(USE_JEMALLOC) && !defined(UNIT_TESTING) +#include "jemalloc/jemalloc.h" +#define malloc(size) je_malloc(size) +#define calloc(count, size) je_calloc(count, size) +#define realloc(ptr, size) je_realloc(ptr, size) +#define free(ptr) je_free(ptr) +#endif + /// Try to free memory. Used when trying to recover from out of memory errors. /// @see {xmalloc} static void try_to_free_memory(void) @@ -368,19 +376,7 @@ size_t xstrlcpy(char *restrict dst, const char *restrict src, size_t size) char *xstrdup(const char *str) FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET { - char *ret = strdup(str); - - if (!ret) { - try_to_free_memory(); - ret = strdup(str); - if (!ret) { - mch_errmsg(e_outofmem); - mch_errmsg("\n"); - preserve_exit(); - } - } - - return ret; + return xmemdupz(str, strlen(str)); } /// A version of memchr that starts the search at `src + len`. |