[vlc-devel] [PATCH 1/1] block: use PAGE_SIZE to determine when to do malloc+memcpy

Rémi Denis-Courmont remi at remlab.net
Sat Oct 4 11:07:01 CEST 2014


Le samedi 4 octobre 2014, 11:44:57 Ilkka Ollakka a écrit :
> ---
>  src/misc/block.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/src/misc/block.c b/src/misc/block.c
> index 0a408cc..5b7ec6b 100644
> --- a/src/misc/block.c
> +++ b/src/misc/block.c
> @@ -123,8 +123,6 @@ static void BlockMetaCopy( block_t *restrict out, const
> block_t *in ) /** Initial reserved header and footer size. */
>  #define BLOCK_PADDING      32
> 
> -/* Maximum size of reserved footer before shrinking with realloc(). */
> -#define BLOCK_WASTE_SIZE   2048
> 
>  block_t *block_Alloc (size_t size)
>  {
> @@ -205,6 +203,13 @@ block_t *block_Realloc( block_t *p_block, ssize_t
> i_prebody, size_t i_body ) uint8_t *p_start = p_block->p_start;
>      uint8_t *p_end = p_start + p_block->i_size;
> 
> +    /* Maximum size of reserved footer before shrinking with realloc().
> +     * FIXME: this is basicly limit where is
> +     * meaningfull to do malloc/memcpy vs wasted memory size, so
> +     * is PAGE_SIZE good limit or should it be n*PAGE_SIZE where n > 1?

"This is basically the threshold from which malloc()/memcpy() actually saves 
memory." ?

> +     */
> +    const long block_waste_size = sysconf( _SC_PAGESIZE );
> +
>      /* Second, reallocate the buffer if we lack space. This is done now to
>       * minimize the payload size for memory copy. */
>      assert( i_prebody >= 0 );
> @@ -227,7 +232,7 @@ block_t *block_Realloc( block_t *p_block, ssize_t
> i_prebody, size_t i_body ) else
>      /* We have a very large reserved footer now? Release some of it.
>       * XXX it might not preserve the alignment of p_buffer */
> -    if( p_end - (p_block->p_buffer + i_body) > BLOCK_WASTE_SIZE )
> +    if( p_end - (p_block->p_buffer + i_body) > block_waste_size )
>      {
>          block_t *p_rea = block_Alloc( requested );
>          if( p_rea )

-- 
Rémi Denis-Courmont
http://www.remlab.net/




More information about the vlc-devel mailing list