Re: Why not use the calloc to replace malloc?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Why not use the calloc to replace malloc?
Дата
Msg-id 3765291.1682222377@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Why not use the calloc to replace malloc?  (Wen Yi <chuxuec@outlook.com>)
Ответы Re: Why not use the calloc to replace malloc?  (Thorsten Glaser <tg@evolvis.org>)
Список pgsql-general
Wen Yi <chuxuec@outlook.com> writes:
> [ use calloc to replace zeroing fields individually ]

The reason we like to do it like that is that it provides greppability,
that is you can search the source code to see where a particular field
is initialized or modified.  The backend code is often intentionally
inefficient in this way: you can find a lot of places that do
makeNode(some-node-type) and then zero out fields within the node, even
though makeNode() always provides a zeroed-out struct.  An important
reason why this is a good idea is that the code isn't dependent on
whether the particular value you need to initialize the field to
happens to be bitwise zeros or something else.

People have complained about this practice off-and-on, but no one has
provided any evidence that there's a significant performance cost.
The maintenance benefits are real though.

            regards, tom lane



В списке pgsql-general по дате отправления:

Предыдущее
От: Wen Yi
Дата:
Сообщение: Why not use the calloc to replace malloc?
Следующее
От: Thorsten Glaser
Дата:
Сообщение: Re: Why not use the calloc to replace malloc?