Liste des Groupes | Revenir à cl c |
Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:No, it's an analogy. You run lots of apps gobbling lots of memory, and maybe a program won't launch or thngs start to slow or a warning comes up, and you realise that soon the program of interest might run out of memory, and so you shut other things down so that that doesn't happen.On 11/03/2024 17:00, Scott Lurndal wrote:If I withdraw 20 pounds from my bank, I'll bet you that 20 pounds thatMalcolm McLean <malcolm.arthur.mclean@gmail.com> writes:The bank has many billions. But there is a banking crisis on and it isOn 10/03/2024 18:47, Scott Lurndal wrote:Actually, your assumptions that:Kaz Kylheku <433-929-6894@kylheku.com> writes:>On 2024-03-10, Michael S <already5chosen@yahoo.com> wrote:>On Sat, 09 Mar 2024 16:37:19 -0800>
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:strdup() and strndup() are being added to the C23 standard.>
>
What is justification?
strdup is required by POSIX already and thus widely implemented.
Many programmers who are not into standards already assume it's in C.
>
For decades, portable programs have been doing things like this:
>
#if HAVE_STRDUP
#define xstrdup(s) strdup(s)
#else
char *xstrdup(const char *); // own definition
#endif
>What strdup() can do better, for any chosen value of better, than>
strlen()+malloc()+memcpy() ?
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
1) strdup is the only allocation function used by an application
2) all strings are "short"
are both flawed.
>
about to fail. And someone, somewhere, will be that man who tries to
withdraw some money and is told "no". But how likely is that man to be
you with your 20 pounds at the cashpoint? How likely is it to be
another bank making a cash call for a 100 million or so?
the bank still checks whether it has the money.
I'd rather write correct code than code that almost certainly happens to
work. Sure, strdup() is unlikely to fail-- but I'm going to check the
result.
And how often do banks fail, actually, and how often does governmentThe government isn't going to intervene when your laptop is running low
take action when it's heading that way, but nowhere near failing yet?
on memory.
Les messages affichés proviennent d'usenet.