Re: Avoid unecessary MemSet call (src/backend/utils/cache/relcache.c)

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
Cc: Justin Pryzby <pryzby(at)telsasoft(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Avoid unecessary MemSet call (src/backend/utils/cache/relcache.c)
Date: 2022-05-18 14:08:08
Message-ID: CAEudQAoU95aq_MD3G4vV7P7m52iXO9GQEairPnLTDM+bqzxtQw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Em qua., 18 de mai. de 2022 às 10:52, Peter Eisentraut <
peter(dot)eisentraut(at)enterprisedb(dot)com> escreveu:

> On 18.05.22 01:18, Justin Pryzby wrote:
> > Take the first one as an example. It says:
> >
> > GenericCosts costs;
> > MemSet(&costs, 0, sizeof(costs));
> >
> > You sent a patch to change it to sizeof(GenericCosts).
> >
> > But it's not a pointer, so they are the same.
>
> This instance can more easily be written as
>
> costs = {0};
>
That would initialize the content at compilation and not at runtime,
correct?
And we would avoid MemSet/memset altogether.

There are a lot of cases using MemSet (with struct variables) and at
Windows 64 bits, long are 4 (four) bytes.
So I believe that MemSet is less efficient on Windows than on Linux.
"The size of the '_vstart' buffer is not a multiple of the element size of
the type 'long'."
message from PVS-Studio static analysis tool.

regards,
Ranier Vilela

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jan Wieck 2022-05-18 14:23:34 Re: Limiting memory allocation
Previous Message Peter Eisentraut 2022-05-18 13:52:15 Re: Avoid unecessary MemSet call (src/backend/utils/cache/relcache.c)