Re: Why not use the calloc to replace malloc? - Mailing list pgsql-general

From Tom Lane
Subject Re: Why not use the calloc to replace malloc?
Date
Msg-id 3765291.1682222377@sss.pgh.pa.us
Whole thread Raw
In response to Why not use the calloc to replace malloc?  (Wen Yi <chuxuec@outlook.com>)
Responses Re: Why not use the calloc to replace malloc?
List 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 by date:

Previous
From: Wen Yi
Date:
Subject: Why not use the calloc to replace malloc?
Next
From: Thorsten Glaser
Date:
Subject: Re: Why not use the calloc to replace malloc?