Re: libpq debug log

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: tsunakawa(dot)takay(at)fujitsu(dot)com
Cc: alvherre(at)alvh(dot)no-ip(dot)org, iwata(dot)aya(at)fujitsu(dot)com, tgl(at)sss(dot)pgh(dot)pa(dot)us, k(dot)jamison(at)fujitsu(dot)com, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: libpq debug log
Date: 2021-03-11 03:11:19
Message-ID: 20210311.121119.232858653132597108.horikyota.ntt@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

At Thu, 11 Mar 2021 03:01:16 +0000, "tsunakawa(dot)takay(at)fujitsu(dot)com" <tsunakawa(dot)takay(at)fujitsu(dot)com> wrote in
> From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
> > The output functions copy message bytes into local variable but the
> > same effect can be obtained by just casing via typed pointer type.
> >
> > uint32 tmp4;
> > ..
> > memcpy(&tmp4, buf + *cursor, 4);
> > result = (int) pg_ntoh32(tmp4);
> >
> > can be written as
> >
> > result = pg_ntoh32(* (uint32 *) (buf + *cursor));
>
> I'm afraid we need to memcpy() because of memory alignment.

Right. So something like this?

unsigned char p;

p = buf + *cursor;
result = (uint32) (*p << 24) + (*(p + 1)) << 16 + ...);

> > I think we can get rid of copying in the output functions for String
> > and Bytes in different ways.
>
> I haven't looked at this code, but you sound right.

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Justin Pryzby 2021-03-11 03:20:57 Re: [HACKERS] Custom compression methods
Previous Message Julien Rouhaud 2021-03-11 03:11:18 Re: Replace buffer I/O locks with condition variables (reviving an old patch)