[FFmpeg-cvslog] mem: add support for _aligned_malloc() as found on Windows

Ronald S. Bultje git at videolan.org
Tue Jun 19 21:13:53 CEST 2012


ffmpeg | branch: master | Ronald S. Bultje <rsbultje at gmail.com> | Mon Jun 18 14:37:02 2012 +0100| [be1a839ca638e308748831fdc6fa0b7a7c8e94cf] | committer: Martin Storsjö

mem: add support for _aligned_malloc() as found on Windows

The check uses check_func_header, since this function is
conditionally available depending on the targeted MSVCRT
version.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=be1a839ca638e308748831fdc6fa0b7a7c8e94cf
---

 configure       |    4 +++-
 libavutil/mem.c |    6 ++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index ea80d48..0baa755 100755
--- a/configure
+++ b/configure
@@ -1051,6 +1051,7 @@ HAVE_LIST="
     $ARCH_EXT_LIST
     $HAVE_LIST_PUB
     $THREADS_LIST
+    aligned_malloc
     aligned_stack
     alsa_asoundlib_h
     altivec_h
@@ -2838,6 +2839,7 @@ check_func  ${malloc_prefix}memalign            && enable memalign
 check_func  mkstemp
 check_func  mmap
 check_func  ${malloc_prefix}posix_memalign      && enable posix_memalign
+check_func_headers malloc.h _aligned_malloc     && enable aligned_malloc
 check_func  setrlimit
 check_func  strerror_r
 check_func  strptime
@@ -3144,7 +3146,7 @@ check_deps $CONFIG_LIST       \
 
 enabled asm || { arch=c; disable $ARCH_LIST $ARCH_EXT_LIST; }
 
-! enabled_any memalign posix_memalign &&
+! enabled_any memalign posix_memalign aligned_malloc &&
     enabled_any $need_memalign && enable memalign_hack
 
 echo "install prefix            $prefix"
diff --git a/libavutil/mem.c b/libavutil/mem.c
index bf1a542..0fe9f54 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -84,6 +84,8 @@ void *av_malloc(size_t size)
 #elif HAVE_POSIX_MEMALIGN
     if (posix_memalign(&ptr,32,size))
         ptr = NULL;
+#elif HAVE_ALIGNED_MALLOC
+    ptr = _aligned_malloc(size, 32);
 #elif HAVE_MEMALIGN
     ptr = memalign(32,size);
     /* Why 64?
@@ -131,6 +133,8 @@ void *av_realloc(void *ptr, size_t size)
     if(!ptr) return av_malloc(size);
     diff= ((char*)ptr)[-1];
     return (char*)realloc((char*)ptr - diff, size + diff) + diff;
+#elif HAVE_ALIGNED_MALLOC
+    return _aligned_realloc(ptr, size, 32);
 #else
     return realloc(ptr, size);
 #endif
@@ -141,6 +145,8 @@ void av_free(void *ptr)
 #if CONFIG_MEMALIGN_HACK
     if (ptr)
         free((char*)ptr - ((char*)ptr)[-1]);
+#elif HAVE_ALIGNED_MALLOC
+    _aligned_free(ptr);
 #else
     free(ptr);
 #endif



More information about the ffmpeg-cvslog mailing list