Sujet : Re: What is your opinion about init_malloc?
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.cDate : 15. Mar 2025, 15:08:57
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vr41lp$3lld2$1@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
Em 3/14/2025 5:06 PM, Kaz Kylheku escreveu:
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 ... */ }
Inside the Mail_Alloc we still have the question how to initialise a const member in the heap.
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.
Someone on reddit suggested this name. I think it makes sense.