Sujet : Re: What is your opinion about init_malloc?
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 14. Mar 2025, 21:06:08
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250314123035.751@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-03-14, Thiago Adams <
thiago.adams@gmail.com> wrote:
What is your opinion about init_malloc?
One problem it solves it to initialise a const objects on heap.
I don't think it's that useful, because I would rather write a
type-specific allocating constructor:
struct Mail *Mail_alloc(int id) { /* ... you know what goes here ... */ }
No games with macros and struct literals that we hope the
compiler optimizes away.
What can be useful is a strdup-like function for duplicating an existing binary
object (i.e. that was not just created and initialized in automatic storage
just for this purpose):
void *memdup(const void *mem, size_t size);
which is like your init_malloc what you have as the basis of the macros.