[Olsr-dev] [PATCH v1 3/8] txtinfo: avoid a memcpy: just move the abuf.buf pointer and clear abuf

Henning Rogge (spam-protected)
Mon Nov 30 11:18:36 CET 2015


On Fri, Nov 27, 2015 at 5:26 PM, Ferry Huberts <(spam-protected)> wrote:
> From: Ferry Huberts <(spam-protected)>
>
> Signed-off-by: Ferry Huberts <(spam-protected)>
> ---
>  lib/txtinfo/src/olsrd_txtinfo.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/lib/txtinfo/src/olsrd_txtinfo.c b/lib/txtinfo/src/olsrd_txtinfo.c
> index 429107b..1c3e860 100644
> --- a/lib/txtinfo/src/olsrd_txtinfo.c
> +++ b/lib/txtinfo/src/olsrd_txtinfo.c
> @@ -831,12 +831,15 @@ static void send_info(unsigned int send_what, int the_socket) {
>    if (send_what & SIW_OLSRD_CONF)
>      ipc_print_olsrd_conf(&abuf);
>
> -  outbuffer[outbuffer_count] = olsr_malloc(abuf.len, PLUGIN_NAME" output buffer");
> +  /* avoid a memcpy: just move the abuf.buf pointer and clear abuf */
> +  outbuffer[outbuffer_count] = abuf.buf;
>    outbuffer_size[outbuffer_count] = abuf.len;
>    outbuffer_written[outbuffer_count] = 0;
>    outbuffer_socket[outbuffer_count] = the_socket;
> +  abuf.buf = NULL;
> +  abuf.len = 0;
> +  abuf.size = 0;
>
> -  memcpy(outbuffer[outbuffer_count], abuf.buf, abuf.len);
>    outbuffer_count++;
>
>    if (outbuffer_count == 1) {

Maybe we should have just made the "outbuffer" an array of autobuf
structs...  Still the patch is an improvement over the old solution.

Henning



More information about the Olsr-dev mailing list