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

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: David Zhang <david(dot)zhang(at)highgo(dot)ca>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, 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-08-20 14:26:53
Message-ID: CAEudQAquRs=v+Azo=RFn8b18SSFquREwuuR5fk6s9Bga2So2+Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Em sex., 19 de ago. de 2022 às 19:27, David Zhang <david(dot)zhang(at)highgo(dot)ca>
escreveu:

> Hi Ranier,
>
Hi David,

>
> Following the comment in commit 9fd45870c1436b477264c0c82eb195df52bc0919,
>
> (The same could be done with appropriate memset() calls, but this
> patch is part of an effort to phase out MemSet(), so it doesn't touch
> memset() calls.)
>
> Should these obviously possible replacement of the standard library
> function "memset" be considered as well?
>
Yes, sure.
In modern C compilers like clang above 13, gcc and msvc the initialization
with {0},
has no problem, because all bits are correctly initialized to zero.

However with some old compilers, such behavior is not strictly followed, so
with structs it is not safe to use.
But especially for arrays, whose use doesn't depend on filling the holes,
it's certainly safe and cheap to use,
which is the case here.

For example, something like the attached one which is focusing on the
> pageinspect extension only.
>
Surely you did, but it has to be said, it was compiled and tested with at
least a make check.
Looks like it's ok, LTGM.

regards,
Ranier Vilela

>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Julien Rouhaud 2022-08-20 14:35:05 Re: Schema variables - new implementation for Postgres 15
Previous Message Ranier Vilela 2022-08-20 14:07:59 Re: Fix typo with logical connector (src/backend/commands/vacuumparallel.c)