[Ffmpeg-devel] [PATCH] move memory functions in avutil

Michael Niedermayer michaelni
Sat Sep 23 15:45:29 CEST 2006


Hi

On Sat, Sep 23, 2006 at 01:39:33AM +0200, Luca Barbato wrote:
> pretty much the $subj
> 
> I left in av_codec the _static ones.
> 
> if is accepted I'll update the postproc one accordingly.
> 
> lu
> 
> -- 
> 
> Luca Barbato
> 
> Gentoo/linux Gentoo/PPC
> http://dev.gentoo.org/~lu_zero
> 

> Index: libavutil/mem.c
> ===================================================================
> --- libavutil/mem.c	(revision 6322)
> +++ libavutil/mem.c	(working copy)
> @@ -135,3 +135,51 @@
>  #endif
>  }
>  
> +/**
> + * Frees memory and sets the pointer to NULL.
> + * @param arg pointer to the pointer which should be freed
> + */
> +void av_freep(void *arg)
> +{
> +    void **ptr= (void**)arg;
> +    av_free(*ptr);
> +    *ptr = NULL;
> +}
> +
> +void *av_mallocz(unsigned int size)
> +{
> +    void *ptr;
> +
> +    ptr = av_malloc(size);
> +    if (!ptr)
> +        return NULL;
> +    memset(ptr, 0, size);
> +    return ptr;

if(ptr) 
    memset()


> +}
> +
> +char *av_strdup(const char *s)
> +{
> +    char *ptr;
> +    int len;
> +    len = strlen(s) + 1;
> +    ptr = av_malloc(len);
> +    if (!ptr)
> +        return NULL;
> +    memcpy(ptr, s, len);
> +    return ptr;

if(ptr)
    memcpy()


> +}
> +
> +/**
> + * realloc which does nothing if the block is large enough
> + */
> +void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
> +{
> +    if(min_size < *size)
> +        return ptr;
> +
> +    *size= FFMAX(17*min_size/16 + 32, min_size);
> +
> +    return av_realloc(ptr, *size);
> +}

i would prefer if av_fast_realloc would not be moved to libavutil yet
one thing which must be done first is to benchmark it, maybe its better
to simply just call av_realloc()


-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In the past you could go to a library and read, borrow or copy any book
Today you'd get arrested for mere telling someone where the library is




More information about the ffmpeg-devel mailing list