<div dir="ltr">On Fri, Nov 21, 2014 at 4:03 AM, Jean-Baptiste Kempf <span dir="ltr"><<a href="mailto:jb@videolan.org" target="_blank">jb@videolan.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Do you see a CPU difference?<br></blockquote><div><br></div><div>Not a huge one in the grand scheme of things, but for a given file, with this patch I get:<br>15 calls to realloc * 234 instructions per call + and 1 call to free * 96 instructions per call = 3606 instructions<br>VS. <br>4872 calls to malloc * 206 instructions per call +  4872 calls to free * 96 instructions per call = 1607760 instructions<br><br></div><div>but it only saves about 0.01% CPU overall.<br><br></div><div>-t<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
On 21 Nov, Tristan Matthews wrote :<br>
<div><div class="h5">> ---<br>
>  modules/packetizer/flac.c | 21 ++++++++++++++-------<br>
>  1 file changed, 14 insertions(+), 7 deletions(-)<br>
><br>
> diff --git a/modules/packetizer/flac.c b/modules/packetizer/flac.c<br>
> index ecf854f..25f1957 100644<br>
> --- a/modules/packetizer/flac.c<br>
> +++ b/modules/packetizer/flac.c<br>
> @@ -90,6 +90,8 @@ struct decoder_sys_t<br>
>      size_t i_frame_size;<br>
>      uint16_t crc;<br>
>      unsigned int i_rate, i_channels, i_bits_per_sample;<br>
> +    size_t i_buf;<br>
> +    uint8_t *p_buf;<br>
>  };<br>
><br>
>  static const int pi_channels_maps[9] =<br>
> @@ -603,19 +605,21 @@ static block_t *Packetize(decoder_t *p_dec, block_t **pp_block)<br>
>      {<br>
>          /* Calculate the initial CRC for the minimal frame size,<br>
>           * We'll update it as we look for the next start code. */<br>
> -        uint8_t *buf = malloc(p_sys->i_frame_size);<br>
> -        if (!buf)<br>
> -            return NULL;<br>
> +        if (p_sys->i_buf < p_sys->i_frame_size)<br>
> +        {<br>
> +            p_sys->p_buf = realloc(p_sys->p_buf, p_sys->i_frame_size);<br>
> +            if (!p_sys->p_buf)<br>
> +                return NULL;<br>
> +            p_sys->i_buf = p_sys->i_frame_size;<br>
> +        }<br>
><br>
> -        if (block_PeekOffsetBytes(&p_sys->bytestream, 0, buf, p_sys->i_frame_size)) {<br>
> -            free(buf);<br>
> +        if (block_PeekOffsetBytes(&p_sys->bytestream, 0, p_sys->p_buf, p_sys->i_frame_size)) {<br>
>              return NULL;<br>
>          }<br>
><br>
>          uint16_t crc = 0;<br>
>          for (unsigned i = 0; i < p_sys->i_frame_size; i++)<br>
> -            crc = flac_crc16(crc, buf[i]);<br>
> -        free(buf);<br>
> +            crc = flac_crc16(crc, p_sys->p_buf[i]);<br>
>          p_sys->crc = crc;<br>
><br>
>          /* Check if next expected frame contains the sync word */<br>
> @@ -752,6 +756,8 @@ static int Open(vlc_object_t *p_this)<br>
>      p_sys->i_state       = STATE_NOSYNC;<br>
>      p_sys->b_stream_info = false;<br>
>      p_sys->i_pts         = VLC_TS_INVALID;<br>
> +    p_sys->i_buf         = 0;<br>
> +    p_sys->p_buf         = NULL;<br>
>      block_BytestreamInit(&p_sys->bytestream);<br>
><br>
>      /* */<br>
> @@ -773,5 +779,6 @@ static void Close(vlc_object_t *p_this)<br>
><br>
>      es_format_Clean(&p_dec->fmt_out);<br>
>      block_BytestreamRelease(&p_sys->bytestream);<br>
> +    free(p_sys->p_buf);<br>
>      free(p_sys);<br>
>  }<br>
> --<br>
> 1.9.3<br>
><br>
</div></div>> _______________________________________________<br>
> vlc-devel mailing list<br>
> To unsubscribe or modify your subscription options:<br>
> <a href="https://mailman.videolan.org/listinfo/vlc-devel" target="_blank">https://mailman.videolan.org/listinfo/vlc-devel</a><br>
<span class=""><font color="#888888"><br>
--<br>
With my kindest regards,<br>
<br>
--<br>
Jean-Baptiste Kempf<br>
<a href="http://www.jbkempf.com/" target="_blank">http://www.jbkempf.com/</a> - <a href="tel:%2B33%20672%20704%20734" value="+33672704734">+33 672 704 734</a><br>
Sent from my Electronic Device<br>
_______________________________________________<br>
vlc-devel mailing list<br>
To unsubscribe or modify your subscription options:<br>
<a href="https://mailman.videolan.org/listinfo/vlc-devel" target="_blank">https://mailman.videolan.org/listinfo/vlc-devel</a><br>
</font></span></blockquote></div><br></div></div>