Hi Patrick
On 24/07/2024 14:11, Patrick Steinhardt wrote:
On Wed, Jul 24, 2024 at 04:46:20AM -0700, Karthik Nayak wrote:
Patrick Steinhardt <ps@xxxxxx> writes:
We semi-regularly have discussions around whether a function shall be
named `release()` or `free()`. For most of the part we use these two
terminologies quite consistently though:
I noticed there is also `clear()` used in some places. Should we also
mention that we don't recommend using `clear()` WRT freeing memory?
In any case I think we should decide on eithe using `clear()` or using
`release()` for consistency's sake. Which of both we use I don't quite
care, but the following very shoddy analysis clearly favors `release()`:
$ git grep '_clear(' | wc -l
844
$ git grep '_release(' | wc -l
2126
I think a fairer comparison would be to look at function declarations,
not all the call sites.
$ { git grep 'void [a-z_]*_release(' '*.h'
git grep 'static void [a-z_]*_release(' '*.c'
} | wc -l
47
$ { git grep 'void [a-z_]*_clear(' '*.h'
git grep 'static void [a-z_]*_clear(' '*.c'
} | wc -l
58
So we have more _clear() functions than _release() functions. I think
there may sometimes be a semantic difference between _clear() and
_release() as well where some _clear() functions zero out the struct
after freeing the members.
Thanks for working on this it will be a useful addition to our coding
guidelines
Best Wishes
Phillip
So yeah, I'm happy to explicitly mention that `clear()` shouldn't be
used in favor of `release()`.
Patrick