Sujet : Re: avoiding strdup()
De : 433-929-6894 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 11. Mar 2024, 18:52:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240311104527.444@kylheku.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-03-11, Scott Lurndal <
scott@slp53.sl.home> wrote:
Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
On 10/03/2024 18:47, Scott Lurndal wrote:
Kaz Kylheku <433-929-6894@kylheku.com> writes:
Not take up space in every application for a common library routine.
It's a form of lazy programming. I've seen a lot of open source
code that uses strdup without checking for failure and frequently
"forgetting" to free the result.
>
And it is probably more likely that machine with many gigabytes of RAM
>
Actually, your assumptions that:
1) strdup is the only allocation function used by an application
2) all strings are "short"
Even if a string is long enough to need its own mmap request,
that will still return valid memory that later fails to commit.
Under overcommit conditions, you will only reliably get null return out
of a large strdup if you've exhausted your local address space
(of which you have lots under 64 bits).
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca