|
From: | Paul Eggert |
Subject: | Re: XMALLOC() et al |
Date: | Fri, 19 Jul 2024 23:41:27 -0700 |
User-agent: | Mozilla Thunderbird |
On 2024-07-19 18:59, Bruno Haible wrote:
GNU gettext uses the XMALLOC macro in more than 100 places. It's just so convenient to do a memory allocation in 1 line of code:
I find it more convenient to write this: context = xmalloc (sizeof *context); than this (taken from GNU gettext): context = XMALLOC (markup_parse_context_ty);not simply because it's easier for a human to read and know instantly that it's right, but because when one changes the type of 'context' one needn't change all corresponding xmalloc calls.
Although XMALLOC has some advantages, all in all in my experience they're outweighed by its disadvantages. I would rather not encourage its use in Gnulib proper.
I know that in some places, such as readutmp.c, you like to optimize several memory allocations into a single one.
Yes, and that flexibility is another advantage of xmalloc etc. over XMALLOC etc.
[Prev in Thread] | Current Thread | [Next in Thread] |