Re: Should we use MemSet or {0} for struct initialization?
От | Junwang Zhao |
---|---|
Тема | Re: Should we use MemSet or {0} for struct initialization? |
Дата | |
Msg-id | CAEG8a3LFWuVzXbHpBuG8+cKp_QdiqMUdEZwX+pEU5ptUOPh1Og@mail.gmail.com обсуждение исходный текст |
Ответ на | Should we use MemSet or {0} for struct initialization? (Richard Guo <guofenglinux@gmail.com>) |
Ответы |
Re: Should we use MemSet or {0} for struct initialization?
|
Список | pgsql-hackers |
On Thu, Aug 31, 2023 at 5:34 PM Richard Guo <guofenglinux@gmail.com> wrote: > > While working on a bug in expandRecordVariable() I noticed that in the > switch statement for case RTE_SUBQUERY we initialize struct ParseState > with {0} while for case RTE_CTE we do that with MemSet. I understand > that there is nothing wrong with this, just cannot get away with the > inconsistency inside the same function (sorry for the nitpicking). > > Do we have a preference for how to initialize structures? From 9fd45870 > it seems that we prefer to {0}. So here is a trivial patch doing that. > And with a rough scan the MemSet calls in pg_stat_get_backend_subxact() > can also be replaced with {0}, so include that in the patch too. > > Thanks > Richard If the struct has padding or aligned, {0} only guarantee the struct members initialized to 0, while memset sets the alignment/padding to 0 as well, but since we will not access the alignment/padding, so they give the same effect. I bet {0} should be faster since there is no function call, but I'm not 100% sure ;) -- Regards Junwang Zhao
В списке pgsql-hackers по дате отправления: