[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 4/8] xalloc: new function xreallocarray
From: |
Bruno Haible |
Subject: |
Re: [PATCH 4/8] xalloc: new function xreallocarray |
Date: |
Thu, 22 Apr 2021 02:18:34 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-206-generic; KDE/5.18.0; x86_64; ; ) |
Paul Eggert wrote:
> + xalloc: new function xreallocarray
> + This effectively replaces xnmalloc, which perhaps should be deprecated.
> + The name xreallocarray should be easier to remember now that
> + reallocarray is a standard GNU function.
I disagree that xnmalloc should be deprecated. In 90% of the cases where
I use xnmalloc() or its macro equivalent XNMALLOC, it's for arrays that
get allocated once and freed once.
xnmalloc and XNMALLOC take 2 arguments, whereas xreallocarray takes 3
arguments. It is often possible to express a function with a simple
interface as a special case of a more complex function. If, in many
use-cases, the simpler function is sufficient, users should not be
forced to understand the more complex function.
No one has ever proposed to deprecate malloc(), although it is a special
case of realloc(). Or to deprecate gettext(), on the grounds that it is
a special case of dcgettext().
Bruno
- [PATCH 1/8] safe-alloc: improve doc, Paul Eggert, 2021/04/19
- [PATCH 2/8] backupfile: simplify via realloc-gnu, Paul Eggert, 2021/04/19
- [PATCH 3/8] group-member: simplify via realloc-gnu, Paul Eggert, 2021/04/19
- [PATCH 4/8] xalloc: new function xreallocarray, Paul Eggert, 2021/04/19
- Re: [PATCH 4/8] xalloc: new function xreallocarray,
Bruno Haible <=
- [PATCH 6/8] safe-alloc: simplify via reallocarray, Paul Eggert, 2021/04/19
- [PATCH 7/8] calloc-gnu: now LGPLv2+, Paul Eggert, 2021/04/19
- [PATCH 8/8] safe-alloc: fix pointer implementation, Paul Eggert, 2021/04/19
- [PATCH 5/8] xalloc-oversized: fix SIZE_MAX optimization bug, Paul Eggert, 2021/04/19
- Re: [PATCH 1/8] safe-alloc: improve doc, Eric Blake, 2021/04/22