Created
April 22, 2012 20:40
-
-
Save rikaardhosein/2466747 to your computer and use it in GitHub Desktop.
libavutil's av_malloc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void *av_malloc(size_t size) | |
{ | |
void *ptr = NULL; | |
#if CONFIG_MEMALIGN_HACK | |
long diff; | |
#endif | |
/* let's disallow possible ambiguous cases */ | |
if (size > (max_alloc_size-32)) | |
return NULL; | |
#if CONFIG_MEMALIGN_HACK | |
ptr = malloc(size+ALIGN); | |
if(!ptr) | |
return ptr; | |
diff= ((-(long)ptr - 1)&(ALIGN-1)) + 1; | |
ptr = (char*)ptr + diff; | |
((char*)ptr)[-1]= diff; | |
#elif HAVE_POSIX_MEMALIGN | |
if (size) //OS X on SDK 10.6 has a broken posix_memalign implementation | |
if (posix_memalign(&ptr,ALIGN,size)) | |
ptr = NULL; | |
#elif HAVE_MEMALIGN | |
ptr = memalign(ALIGN,size); | |
#else | |
ptr = malloc(size); | |
#endif | |
if(!ptr && !size) | |
ptr= av_malloc(1); | |
return ptr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment