---
It does use the experimental api to have a proper av_realloc.
Works nicely to extract information and is quite fast.
configure | 2 ++
libavutil/mem.c | 29 +++++++++++++++++++++++++----
2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/configure b/configure
index b4ffbe6..0c6c6fe 100755
--- a/configure
+++ b/configure
@@ -1029,6 +1029,7 @@ CONFIG_LIST="
gpl
gray
hardcoded_tables
+ jemalloc
libcdio
libdc1394
libfaac
@@ -3471,6 +3472,7 @@ done
enabled avisynth && require2 vfw32 "windows.h vfw.h" AVIFileInit -lavifil32
enabled frei0r && { check_header frei0r.h || die "ERROR: frei0r.h header
not found"; }
enabled gnutls && require_pkg_config gnutls gnutls/gnutls.h
gnutls_global_init
+enabled jemalloc && require2 jemalloc "jemalloc/jemalloc.h" rallocm
-ljemalloc
enabled libfaac && require2 libfaac "stdint.h faac.h" faacEncGetVersion
-lfaac
enabled libfdk_aac && require libfdk_aac fdk-aac/aacenc_lib.h aacEncOpen
-lfdk-aac
enabled libfreetype && require_pkg_config freetype2 "ft2build.h
freetype/freetype.h" FT_Init_FreeType
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 3a4433d..cf4281e 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -30,10 +30,15 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
-#if HAVE_MALLOC_H
+#if CONFIG_JEMALLOC
+#include <jemalloc/jemalloc.h>
+#elif HAVE_MALLOC_H
#include <malloc.h>
#endif
+
+
+
#include "avutil.h"
#include "intreadwrite.h"
#include "mem.h"
@@ -69,7 +74,10 @@ void *av_malloc(size_t size)
if (size > (INT_MAX - 32) || !size)
return NULL;
-#if CONFIG_MEMALIGN_HACK
+#if CONFIG_JEMALLOC
+ if (allocm(&ptr, NULL, size, ALLOCM_ALIGN(32)))
+ ptr = NULL;
+#elif CONFIG_MEMALIGN_HACK
ptr = malloc(size + 32);
if (!ptr)
return ptr;
@@ -123,7 +131,17 @@ void *av_realloc(void *ptr, size_t size)
if (size > (INT_MAX - 16))
return NULL;
-#if CONFIG_MEMALIGN_HACK
+#if CONFIG_JEMALLOC
+ if (!size) {
+ av_free(ptr);
+ return NULL;
+ }
+ if (!ptr)
+ return av_malloc(size);
+ if (rallocm(&ptr, NULL, size, 0, ALLOCM_ALIGN(32)))
+ return NULL;
+ return ptr;
+#elif CONFIG_MEMALIGN_HACK
//FIXME this isn't aligned correctly, though it probably isn't needed
if (!ptr)
return av_malloc(size);
@@ -138,7 +156,10 @@ void *av_realloc(void *ptr, size_t size)
void av_free(void *ptr)
{
-#if CONFIG_MEMALIGN_HACK
+#if CONFIG_JEMALLOC
+ if (ptr)
+ dallocm(ptr, ALLOCM_ALIGN(32));
+#elif CONFIG_MEMALIGN_HACK
if (ptr)
free((char *)ptr - ((char *)ptr)[-1]);
#elif HAVE_ALIGNED_MALLOC
--
1.8.0.2
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel