Re: avoiding strdup()

Liste des GroupesRevenir à cl c  
Sujet : Re: avoiding strdup()
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.c
Date : 11. Mar 2024, 20:28:15
Autres entêtes
Organisation : None to speak of
Message-ID : <87msr4aaio.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Kaz Kylheku <433-929-6894@kylheku.com> writes:
On 2024-03-11, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
Michael S <already5chosen@yahoo.com> writes:
[...]
Is there any chance at all that on typical Linux machine (i.e. the one
configured to overcommit virtual memory) strdup() returns NULL?
If it was malloc() I'd say - no chance. For strdup() I'm less sure.
>
strdup() calls malloc(), so strdup() can return NULL if and only if
malloc() can return NULL -- but with the additional constraint that you
first need to have a string argument to strdup() that's long enough to
cause a suffiently large argument to be passed to malloc().
>
One data point: On my Ubuntu system, malloc(SIZE_MAX) returns NULL for
very large arguments (over about 23 GiB in my quick and dirty test).
>
I'm guessing that might be only be because of the overcommit_ratio
value; i.e that allowing a 23 GiB increment in the allocated address
space would bring the system over the currently configured overcommit
ratio.

Good guess, but I don't think so.

    $ cat /proc/sys/vm/overcommit_memory
    0
    $ cat /proc/sys/vm/overcommit_ratio
    50

(These are the default values.)  If I'm reading the proc(5) man page
correctly (which is questionable), 0 means "heuristic overcommit", and
overcommit_ratio is ignored unless the mode is set to 2.

I have 12 GB of physical memory.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Date Sujet#  Auteur
7 Mar 24 * Re: [OT] UTF-8 sig. Was: "White House to Developers: Using C or C++ Invites Cybersecurity Risks"51Ben
9 Mar 24 `* Re: [OT] UTF-8 sig. Was: "White House to Developers: Using C or C++ Invites Cybersecurity Risks"50Blue-Maned_Hawk
9 Mar 24  +* Re: [OT] UTF-8 sig. Was: "White House to Developers: Using C or C++ Invites Cybersecurity Risks"5Keith Thompson
9 Mar 24  i`* Re: [OT] UTF-8 sig. Was: "White House to Developers: Using C or C++ Invites Cybersecurity Risks"4Blue-Maned_Hawk
9 Mar 24  i `* Re: [OT] UTF-8 sig.3vallor
10 Mar 24  i  `* Re: [OT] UTF-8 sig.2Blue-Maned_Hawk
21 Mar 24  i   `- Re: [OT] UTF-8 sig.1Anton Shepelev
9 Mar 24  `* Re: [OT] UTF-8 sig.44Ben
9 Mar 24   +* Re: [OT] UTF-8 sig.3Richard Harnden
10 Mar 24   i`* Re: [OT] UTF-8 sig.2Ben Bacarisse
10 Mar 24   i `- Re: [OT] UTF-8 sig.1Richard Harnden
9 Mar 24   +* Re: [OT] UTF-8 sig.7Blue-Maned_Hawk
9 Mar 24   i`* Re: [OT] UTF-8 sig.6Richard Harnden
10 Mar 24   i +- Re: [OT] UTF-8 sig.1Blue-Maned_Hawk
10 Mar 24   i `* Re: [OT] UTF-8 sig.4Ben Bacarisse
10 Mar 24   i  `* Re: [OT] UTF-8 sig.3Michael S
10 Mar 24   i   +- Re: [OT] UTF-8 sig.1Blue-Maned_Hawk
10 Mar 24   i   `- Re: [OT] UTF-8 sig.1Kaz Kylheku
9 Mar 24   `* avoiding strdup() (was: Re: [OT] UTF-8 sig.)33vallor
9 Mar 24    +- Re: avoiding strdup()1Spiros Bousbouras
10 Mar 24    +* Re: avoiding strdup()30Keith Thompson
10 Mar 24    i`* Re: avoiding strdup()29Michael S
10 Mar 24    i +- Re: avoiding strdup()1Blue-Maned_Hawk
10 Mar 24    i `* Re: avoiding strdup()27Kaz Kylheku
10 Mar 24    i  +- Re: avoiding strdup()1Richard Harnden
11 Mar 24    i  +* Re: avoiding strdup()22Malcolm McLean
11 Mar 24    i  i+* Re: avoiding strdup()10Michael S
11 Mar 24    i  ii+* Re: avoiding strdup()6Keith Thompson
11 Mar 24    i  iii+* Re: avoiding strdup()2Kaz Kylheku
11 Mar 24    i  iiii`- Re: avoiding strdup()1Keith Thompson
11 Mar 24    i  iii+- Re: avoiding strdup()1Keith Thompson
11 Mar 24    i  iii`* Re: avoiding strdup()2Spiros Bousbouras
11 Mar 24    i  iii `- Re: avoiding strdup()1Keith Thompson
11 Mar 24    i  ii`* Re: avoiding strdup()3Michael S
11 Mar 24    i  ii +- Re: avoiding strdup()1Michael S
11 Mar 24    i  ii `- Re: avoiding strdup()1Spiros Bousbouras
11 Mar 24    i  i+* Re: avoiding strdup()3Kaz Kylheku
11 Mar 24    i  ii`* Re: avoiding strdup()2Richard Kettlewell
11 Mar 24    i  ii `- Re: avoiding strdup()1Keith Thompson
12 Mar 24    i  i`* Re: avoiding strdup()8Malcolm McLean
12 Mar 24    i  i `* Re: avoiding strdup()7Keith Thompson
12 Mar 24    i  i  +* Re: avoiding strdup()3Malcolm McLean
13 Mar 24    i  i  i`* Re: avoiding strdup()2Keith Thompson
13 Mar 24    i  i  i `- Re: avoiding strdup()1Malcolm McLean
13 Mar 24    i  i  `* Re: avoiding strdup()3Malcolm McLean
13 Mar 24    i  i   `* Re: avoiding strdup()2James Kuyper
13 Mar 24    i  i    `- Re: avoiding strdup()1David Brown
29 Apr 24    i  `* Re: avoiding strdup()3Lawrence D'Oliveiro
29 Apr 24    i   `* Re: avoiding strdup()2i
1 May 24    i    `- Re: avoiding strdup()1steve
10 Mar 24    `- Re: avoiding strdup()1Richard Harnden

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal