Re: Avoid unecessary MemSet call (src/backend/utils/cache/relcache.c) - Mailing list pgsql-hackers

From Ranier Vilela
Subject Re: Avoid unecessary MemSet call (src/backend/utils/cache/relcache.c)
Date
Msg-id CAEudQAquRs=v+Azo=RFn8b18SSFquREwuuR5fk6s9Bga2So2+Q@mail.gmail.com
Whole thread Raw
In response to Re: Avoid unecessary MemSet call (src/backend/utils/cache/relcache.c)  (David Zhang <david.zhang@highgo.ca>)
List pgsql-hackers
Em sex., 19 de ago. de 2022 às 19:27, David Zhang <david.zhang@highgo.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

pgsql-hackers by date:

Previous
From: Ranier Vilela
Date:
Subject: Re: Fix typo with logical connector (src/backend/commands/vacuumparallel.c)
Next
From: Julien Rouhaud
Date:
Subject: Re: Schema variables - new implementation for Postgres 15