Search Postgresql Archives

Re: Why not use the calloc to replace malloc?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Wen Yi <chuxuec@xxxxxxxxxxx> 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





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux