Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Experience varies directly with equipment ruined.


devel / comp.lang.c / The return value of realloc(p,0)

SubjectAuthor
* The return value of realloc(p,0)Kenny McCormack
+* Re: The return value of realloc(p,0)Richard Damon
|+* Re: The return value of realloc(p,0)Tim Rentsch
||`- Re: The return value of realloc(p,0)Scott Lurndal
|`* Re: The return value of realloc(p,0)Robert Latest
| `* Re: The return value of realloc(p,0)Tim Rentsch
|  `* Re: The return value of realloc(p,0)Vir Campestris
|   `* Re: The return value of realloc(p,0)Tim Rentsch
|    +* Re: The return value of realloc(p,0)Vir Campestris
|    |+- Re: The return value of realloc(p,0)Kaz Kylheku
|    |`* Re: The return value of realloc(p,0)Tim Rentsch
|    | +* Re: The return value of realloc(p,0)Scott Lurndal
|    | |`* Re: The return value of realloc(p,0)Tim Rentsch
|    | | `* Re: The return value of realloc(p,0)Scott Lurndal
|    | |  `* Re: The return value of realloc(p,0)Tim Rentsch
|    | |   `* Re: The return value of realloc(p,0)Scott Lurndal
|    | |    +* Re: The return value of realloc(p,0)Spiros Bousbouras
|    | |    |`- Re: The return value of realloc(p,0)Malcolm McLean
|    | |    +* Re: The return value of realloc(p,0)Tim Rentsch
|    | |    |`* Re: The return value of realloc(p,0)Scott Lurndal
|    | |    | `- Re: The return value of realloc(p,0)Tim Rentsch
|    | |    `- Re: The return value of realloc(p,0)Vir Campestris
|    | `- Re: The return value of realloc(p,0)Vir Campestris
|    `* Re: The return value of realloc(p,0)Kaz Kylheku
|     +* Re: The return value of realloc(p,0)Lew Pitcher
|     |+* Re: The return value of realloc(p,0)Kaz Kylheku
|     ||`- Re: The return value of realloc(p,0)Lew Pitcher
|     |`* Re: The return value of realloc(p,0)Tim Rentsch
|     | `* Re: The return value of realloc(p,0)Kaz Kylheku
|     |  `- Re: The return value of realloc(p,0)Tim Rentsch
|     `- Re: The return value of realloc(p,0)Tim Rentsch
+* Re: The return value of realloc(p,0)Chris M. Thomasson
|`* Re: The return value of realloc(p,0)Malcolm McLean
| `* Re: The return value of realloc(p,0)Ben Bacarisse
|  `* Re: The return value of realloc(p,0)Chris M. Thomasson
|   `- Re: The return value of realloc(p,0)Chris M. Thomasson
`* Re: The return value of realloc(p,0)Tim Rentsch
 `- Re: The return value of realloc(p,0)Scott Lurndal

Pages:12
The return value of realloc(p,0)

<ua63if$2u50c$2@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=26841&group=comp.lang.c#26841

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: The return value of realloc(p,0)
Date: Sun, 30 Jul 2023 16:36:31 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <ua63if$2u50c$2@news.xmission.com>
Injection-Date: Sun, 30 Jul 2023 16:36:31 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3085324"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Sun, 30 Jul 2023 16:36 UTC

(Inspired by a sub-thread in one or another of the usual, interminable
navel-gazing threads for which CLC is justly famous...)

(On my system) "man realloc" says that:

If size was equal to 0, either NULL or a pointer suitable to be passed
to free() is returned.

which is odd, since, although the standard says either one is legal, the
implementation ought to know. Experimentation indicates that the answer is
the former (NULL).

But what I find interesting is the wording of the second alternative.
Earlier on, it says that the above call (realloc(p,0)) is equivalent to
free(p). So, that means that once the call is made, the pointer is no
longer valid. The text quoted above indicates that whatever is returned by
the call (if not NULL) is valid to be passed to free(). But wouldn't that
(doing so) lead to a dreaded "double free" ?

Note: I may have left some T's uncrossed and/or some I's undotted, but I am
running out of time, so I must cut this short. Rest assured that I have
considered all the possibilities, even if I have not delineated them all
here.

--
"Remember when teachers, public employees, Planned Parenthood, NPR and PBS
crashed the stock market, wiped out half of our 401Ks, took trillions in
TARP money, spilled oil in the Gulf of Mexico, gave themselves billions in
bonuses, and paid no taxes? Yeah, me neither."

Re: The return value of realloc(p,0)

<DeyxM.134678$ens9.28488@fx45.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=26844&group=comp.lang.c#26844

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx45.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: The return value of realloc(p,0)
Content-Language: en-US
Newsgroups: comp.lang.c
References: <ua63if$2u50c$2@news.xmission.com>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <ua63if$2u50c$2@news.xmission.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 50
Message-ID: <DeyxM.134678$ens9.28488@fx45.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sun, 30 Jul 2023 14:46:58 -0400
X-Received-Bytes: 3392
 by: Richard Damon - Sun, 30 Jul 2023 18:46 UTC

On 7/30/23 12:36 PM, Kenny McCormack wrote:
> (Inspired by a sub-thread in one or another of the usual, interminable
> navel-gazing threads for which CLC is justly famous...)
>
> (On my system) "man realloc" says that:
>
> If size was equal to 0, either NULL or a pointer suitable to be passed
> to free() is returned.
>
> which is odd, since, although the standard says either one is legal, the
> implementation ought to know. Experimentation indicates that the answer is
> the former (NULL).
>
> But what I find interesting is the wording of the second alternative.
> Earlier on, it says that the above call (realloc(p,0)) is equivalent to
> free(p). So, that means that once the call is made, the pointer is no
> longer valid. The text quoted above indicates that whatever is returned by
> the call (if not NULL) is valid to be passed to free(). But wouldn't that
> (doing so) lead to a dreaded "double free" ?
>
> Note: I may have left some T's uncrossed and/or some I's undotted, but I am
> running out of time, so I must cut this short. Rest assured that I have
> considered all the possibilities, even if I have not delineated them all
> here.
>

My understanding is that, in effect, the call to realloc(p,0), if it is
using the second option of returning a suitable pointer, is effectively
do a free(p), and then allocating a "0 byte" block of memory and
returning the address of that. this pointer might have the same value as
the input pointer, or it might not. Calling free on the returned pointer
is allowed, and in fact needed to avoid a memory leak (of 0 bytes +
overhead) but calling free on the input pointer (unless the return
happens to match it) would be undefined behavior, as it was freed.

This is just like ANY use of the input pointer after the call, as it
might no longer be valid, unless of course, the return pointer happened
to match the input pointer as it was able to do the operation "in place".

As to why the document both behaviors, it may be that they support
multiple implementation libraries, and don't want to restrict them more
than the Standard does. It is NOT "Impleentation Defined Behavor" as to
which it does, it is just Unspecified, so the implementation can do
either, and could in fact do both at different times.

This just goes back to the Standards Committee not wanting to take sides
in a philosophical debate about 0-byte objects back when this came up,
and then not wanting to break code that depends on either behavior, such
code just needs to use implementations that promise the behavior they
depend on.

Re: The return value of realloc(p,0)

<ua6cnc$30dbn$6@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=26845&group=comp.lang.c#26845

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Sun, 30 Jul 2023 12:12:44 -0700
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <ua6cnc$30dbn$6@dont-email.me>
References: <ua63if$2u50c$2@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 30 Jul 2023 19:12:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cd71dc00a2eb6664fbb78c38275530f3";
logging-data="3159415"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4T9cXklFVO6gtDNlDpcNo5ZXi5PvBjgA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:8iYmBr+OzkwT+OCBQYMxMamzN5w=
Content-Language: en-US
In-Reply-To: <ua63if$2u50c$2@news.xmission.com>
 by: Chris M. Thomasson - Sun, 30 Jul 2023 19:12 UTC

On 7/30/2023 9:36 AM, Kenny McCormack wrote:
> (Inspired by a sub-thread in one or another of the usual, interminable
> navel-gazing threads for which CLC is justly famous...)
>
> (On my system) "man realloc" says that:
>
> If size was equal to 0, either NULL or a pointer suitable to be passed
> to free() is returned.
>
> which is odd, since, although the standard says either one is legal, the
> implementation ought to know. Experimentation indicates that the answer is
> the former (NULL).
>
> But what I find interesting is the wording of the second alternative.
> Earlier on, it says that the above call (realloc(p,0)) is equivalent to
> free(p). So, that means that once the call is made, the pointer is no
> longer valid. The text quoted above indicates that whatever is returned by
> the call (if not NULL) is valid to be passed to free(). But wouldn't that
> (doing so) lead to a dreaded "double free" ?
>
> Note: I may have left some T's uncrossed and/or some I's undotted, but I am
> running out of time, so I must cut this short. Rest assured that I have
> considered all the possibilities, even if I have not delineated them all
> here.
>

void* p = realloc(p,0);
free(p);

Is fine. free(NULL) is fine.

Even if p is not NULL, it still can be passed to free. Keep in mind that
if p is not NULL it should never be used because its pointing to no
memory at all. What am I missing here?

Thanks.

Re: The return value of realloc(p,0)

<3bfac81a-5bdd-4be7-b2e6-c4a0ee4f68c0n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=26856&group=comp.lang.c#26856

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:440e:b0:40f:91be:b62a with SMTP id ka14-20020a05622a440e00b0040f91beb62amr8807qtb.6.1690794981721;
Mon, 31 Jul 2023 02:16:21 -0700 (PDT)
X-Received: by 2002:a05:6870:c98d:b0:1b3:ecdb:ff21 with SMTP id
hi13-20020a056870c98d00b001b3ecdbff21mr18515188oab.3.1690794981392; Mon, 31
Jul 2023 02:16:21 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 31 Jul 2023 02:16:21 -0700 (PDT)
In-Reply-To: <ua6cnc$30dbn$6@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:1c70:988a:9a4c:dd97;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:1c70:988a:9a4c:dd97
References: <ua63if$2u50c$2@news.xmission.com> <ua6cnc$30dbn$6@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3bfac81a-5bdd-4be7-b2e6-c4a0ee4f68c0n@googlegroups.com>
Subject: Re: The return value of realloc(p,0)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Mon, 31 Jul 2023 09:16:21 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3313
 by: Malcolm McLean - Mon, 31 Jul 2023 09:16 UTC

On Sunday, 30 July 2023 at 20:12:58 UTC+1, Chris M. Thomasson wrote:
> On 7/30/2023 9:36 AM, Kenny McCormack wrote:
> > (Inspired by a sub-thread in one or another of the usual, interminable
> > navel-gazing threads for which CLC is justly famous...)
> >
> > (On my system) "man realloc" says that:
> >
> > If size was equal to 0, either NULL or a pointer suitable to be passed
> > to free() is returned.
> >
> > which is odd, since, although the standard says either one is legal, the
> > implementation ought to know. Experimentation indicates that the answer is
> > the former (NULL).
> >
> > But what I find interesting is the wording of the second alternative.
> > Earlier on, it says that the above call (realloc(p,0)) is equivalent to
> > free(p). So, that means that once the call is made, the pointer is no
> > longer valid. The text quoted above indicates that whatever is returned by
> > the call (if not NULL) is valid to be passed to free(). But wouldn't that
> > (doing so) lead to a dreaded "double free" ?
> >
> > Note: I may have left some T's uncrossed and/or some I's undotted, but I am
> > running out of time, so I must cut this short. Rest assured that I have
> > considered all the possibilities, even if I have not delineated them all
> > here.
> >
> void* p = realloc(p,0);
> free(p);
>
> Is fine. free(NULL) is fine.
>
> Even if p is not NULL, it still can be passed to free. Keep in mind that
> if p is not NULL it should never be used because its pointing to no
> memory at all. What am I missing here?
>
p is a valid pointer, but to a buffer of zero bytes. So it can be passed to any
function expecting a buffer, as long as that function is written to handle the
N ==0 case properly.
If we have this code.
unsigned char randomjunk[sizeof(void*)];
mempcy(&p, randomjunk, sizeof(void *));
functionexpectingabuffer(p, 0);

Then it's UB because the system can pick up that we're loading random junk
into an address register and trigger some sort of memory protection.

However is p is returned from realloc(ptr, 0) then it's OK.

Re: The return value of realloc(p,0)

<87cz08w18i.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=26871&group=comp.lang.c#26871

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Mon, 31 Jul 2023 16:26:53 +0100
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <87cz08w18i.fsf@bsb.me.uk>
References: <ua63if$2u50c$2@news.xmission.com> <ua6cnc$30dbn$6@dont-email.me>
<3bfac81a-5bdd-4be7-b2e6-c4a0ee4f68c0n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="b326b269c93766db184fda50f82c858f";
logging-data="3483988"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Ogu+6urg6D2r89hjToYtVU0k4kOZiHhY="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:tp8CFXJq96rNs00yj/y0l5EKej8=
sha1:VtcxE1h46IDGP8wKxStE96ga928=
X-BSB-Auth: 1.24a7824ee888c7f79344.20230731162653BST.87cz08w18i.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 31 Jul 2023 15:26 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:

> On Sunday, 30 July 2023 at 20:12:58 UTC+1, Chris M. Thomasson wrote:

>> void* p = realloc(p,0);

Danger Will Robinson! This is UB: p is indeterminate when passed to
realloc.

>> free(p);
>>
>> Is fine. free(NULL) is fine.
>>
>> Even if p is not NULL, it still can be passed to free. Keep in mind that
>> if p is not NULL it should never be used because its pointing to no
>> memory at all. What am I missing here?

Yes. If p in either NULL or a valid pointer from a prior allocation,
then

p = realloc(p, 0);
free(p);

is fine which was the point you wanted to make. It's unfortunate that
your example had an unrelated problem.

> p is a valid pointer, but to a buffer of zero bytes. So it can be
> passed to any function expecting a buffer, as long as that function is
> written to handle the N ==0 case properly.
> If we have this code.
> unsigned char randomjunk[sizeof(void*)];
> mempcy(&p, randomjunk, sizeof(void *));
> functionexpectingabuffer(p, 0);
>
> Then it's UB because the system can pick up that we're loading random junk
> into an address register and trigger some sort of memory protection.

I see you have decided to join Bart in misusing the term UB. That code
is UB regardless of what the system can or can't do. It's UB because
the language standard says you can't expect any defined behaviour from
that code.

Also, your supposed "reason" could lead readers astray. There is no UB
in this:

unsigned char randomjunk[sizeof (void*)];
mempcy(&p, randomjunk, sizeof p);

The undefined behaviour comes from /any/ access to the value in p after
this, even if that access does not involve it being treated as an
address. The confusion comes from the fact "loading random junk into an
address register" might be taken to refer to these lines, not the
passing of p to a function. After all, there no reason to think that
the code you show will result in a junk value getting into an address
register.

--
Ben.

Re: The return value of realloc(p,0)

<ua99ft$3cuas$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=26887&group=comp.lang.c#26887

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Mon, 31 Jul 2023 14:35:57 -0700
Organization: A noiseless patient Spider
Lines: 73
Message-ID: <ua99ft$3cuas$1@dont-email.me>
References: <ua63if$2u50c$2@news.xmission.com> <ua6cnc$30dbn$6@dont-email.me>
<3bfac81a-5bdd-4be7-b2e6-c4a0ee4f68c0n@googlegroups.com>
<87cz08w18i.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 31 Jul 2023 21:35:57 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4a4b7044b62dfd75cc9233ad5dc1fea1";
logging-data="3570012"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+oZNANHLDECgakzTov1Cjx+hys3lO3GhE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:ltaay3jlrBR7/unxNo9unlubNZ0=
In-Reply-To: <87cz08w18i.fsf@bsb.me.uk>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 31 Jul 2023 21:35 UTC

On 7/31/2023 8:26 AM, Ben Bacarisse wrote:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>
>> On Sunday, 30 July 2023 at 20:12:58 UTC+1, Chris M. Thomasson wrote:
>
>>> void* p = realloc(p,0);
>
> Danger Will Robinson! This is UB: p is indeterminate when passed to
> realloc.

AHHH SHIT!!!

void* b = realloc(a, 0);

God damn it! Sorry!

>
>>> free(p);
>>>
>>> Is fine. free(NULL) is fine.
>>>
>>> Even if p is not NULL, it still can be passed to free. Keep in mind that
>>> if p is not NULL it should never be used because its pointing to no
>>> memory at all. What am I missing here?
>
> Yes. If p in either NULL or a valid pointer from a prior allocation,
> then
>
> p = realloc(p, 0);
> free(p);
>
> is fine which was the point you wanted to make. It's unfortunate that
> your example had an unrelated problem.

Yeah. Shit happens. Thanks for the heads up, Ben. God Damn it.

>
>> p is a valid pointer, but to a buffer of zero bytes. So it can be
>> passed to any function expecting a buffer, as long as that function is
>> written to handle the N ==0 case properly.
>> If we have this code.
>> unsigned char randomjunk[sizeof(void*)];
>> mempcy(&p, randomjunk, sizeof(void *));
>> functionexpectingabuffer(p, 0);
>>
>> Then it's UB because the system can pick up that we're loading random junk
>> into an address register and trigger some sort of memory protection.
>
> I see you have decided to join Bart in misusing the term UB. That code
> is UB regardless of what the system can or can't do. It's UB because
> the language standard says you can't expect any defined behaviour from
> that code.
>
> Also, your supposed "reason" could lead readers astray. There is no UB
> in this:
>
> unsigned char randomjunk[sizeof (void*)];
> mempcy(&p, randomjunk, sizeof p);
>
> The undefined behaviour comes from /any/ access to the value in p after
> this, even if that access does not involve it being treated as an
> address. The confusion comes from the fact "loading random junk into an
> address register" might be taken to refer to these lines, not the
> passing of p to a function. After all, there no reason to think that
> the code you show will result in a junk value getting into an address
> register.
>

Re: The return value of realloc(p,0)

<ua99ih$3cuas$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=26888&group=comp.lang.c#26888

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Mon, 31 Jul 2023 14:37:21 -0700
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <ua99ih$3cuas$2@dont-email.me>
References: <ua63if$2u50c$2@news.xmission.com> <ua6cnc$30dbn$6@dont-email.me>
<3bfac81a-5bdd-4be7-b2e6-c4a0ee4f68c0n@googlegroups.com>
<87cz08w18i.fsf@bsb.me.uk> <ua99ft$3cuas$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 31 Jul 2023 21:37:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4a4b7044b62dfd75cc9233ad5dc1fea1";
logging-data="3570012"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wOkkfN2WOaVnaM5JpZz4a++SsFwt4EzQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:/CCx1FeepYbWj3cg77vV17VvcaE=
In-Reply-To: <ua99ft$3cuas$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 31 Jul 2023 21:37 UTC

On 7/31/2023 2:35 PM, Chris M. Thomasson wrote:
> On 7/31/2023 8:26 AM, Ben Bacarisse wrote:
>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>
>>> On Sunday, 30 July 2023 at 20:12:58 UTC+1, Chris M. Thomasson wrote:
>>
>>>> void* p = realloc(p,0);
>>
>> Danger Will Robinson!  This is UB: p is indeterminate when passed to
>> realloc.

Face palm! How about danger Roger Wilco from SpaceQuest! ;^o

ARGGHHH!

>
> AHHH SHIT!!!
>
> void* b = realloc(a, 0);
>
> God damn it! Sorry!
[...]

Re: The return value of realloc(p,0)

<86v8dvgwlv.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=26980&group=comp.lang.c#26980

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Thu, 03 Aug 2023 23:17:16 -0700
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <86v8dvgwlv.fsf@linuxsc.com>
References: <ua63if$2u50c$2@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="7a95792a6e880c00df8e418e5a126a38";
logging-data="1243314"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/DrM9E6hnpvXDo/dxEO7Wn+ptiWu+flok="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:EKGjPjEOPbbuDm0bLDTdk5H49jY=
sha1:SviaX23e7giC9AruoTfiyYwZ9Vw=
 by: Tim Rentsch - Fri, 4 Aug 2023 06:17 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:

> (On my system) "man realloc" says that:
>
> If size was equal to 0, either NULL or a pointer suitable to
> be passed to free() is returned.
>
> which is odd, since, although the standard says either one is
> legal, the implementation ought to know. [...]

Probably the man page was written to express both possibilities,
so it could be used without change in different distributions.
Normally man pages are separate from whatever C implementation
is present; indeed there may be more than one, with different
choices made in the different implementations.

> But what I find interesting is the wording of the second
> alternative. Earlier on, it says that the above call
> (realloc(p,0)) is equivalent to free(p). [...]

The man page is either wrong or poorly written. I expect most
people have seen plenty of cases where what a man page says does
not exactly match what the C standard mandates.

Re: The return value of realloc(p,0)

<86r0ojgvux.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=26981&group=comp.lang.c#26981

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Thu, 03 Aug 2023 23:33:26 -0700
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <86r0ojgvux.fsf@linuxsc.com>
References: <ua63if$2u50c$2@news.xmission.com> <DeyxM.134678$ens9.28488@fx45.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="7a95792a6e880c00df8e418e5a126a38";
logging-data="1247365"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/N21AMJGBQot46XX7XKZMe629r7gGRmuY="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:PvMpakJ4kziausdySrGP/OiNTi0=
sha1:wAoz3A5r7K6SZ0xZCMYuXeyf60o=
 by: Tim Rentsch - Fri, 4 Aug 2023 06:33 UTC

Richard Damon <Richard@Damon-Family.org> writes:

> On 7/30/23 12:36 PM, Kenny McCormack wrote:
>
>> (On my system) "man realloc" says that:
>>
>> If size was equal to 0, either NULL or a pointer suitable to
>> be passed to free() is returned.
>>
>> which is odd, since, although the standard says either one is
>> legal, the implementation ought to know.

[...]

> As to why the document both behaviors, it may be that they support
> multiple implementation libraries, and don't want to restrict them
> more than the Standard does. It is NOT "Impleentation Defined
> Behavor" as to which it does, it is just Unspecified, so the
> implementation can do either, and could in fact do both at
> different times.

The choice for whether an allocation (or reallocation) of size 0
returns a null pointer or a "unique pointer" has been implementation
defined since C90: section 7.10.3 paragraph 1 in C90, 7.20.3 p1 in
n1256 for C99, and 7.22.3 p1 in n1570 for C11.

Re: The return value of realloc(p,0)

<px7zM.474555$GMN3.222566@fx16.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27004&group=comp.lang.c#27004

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx16.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: The return value of realloc(p,0)
Newsgroups: comp.lang.c
References: <ua63if$2u50c$2@news.xmission.com> <86v8dvgwlv.fsf@linuxsc.com>
Lines: 22
Message-ID: <px7zM.474555$GMN3.222566@fx16.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 04 Aug 2023 14:01:57 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 04 Aug 2023 14:01:57 GMT
X-Received-Bytes: 1511
 by: Scott Lurndal - Fri, 4 Aug 2023 14:01 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>gazelle@shell.xmission.com (Kenny McCormack) writes:
>
>> (On my system) "man realloc" says that:
>>
>> If size was equal to 0, either NULL or a pointer suitable to
>> be passed to free() is returned.
>>
>> which is odd, since, although the standard says either one is
>> legal, the implementation ought to know. [...]
>
>Probably the man page was written to express both possibilities,
>so it could be used without change in different distributions.
>Normally man pages are separate from whatever C implementation
>is present; indeed there may be more than one, with different
>choices made in the different implementations.

Some linux distributions simply provide the POSIX/SuS pages
rather than developing their own set of manual pages. Thus
the page will have generic elements not necessarily specific to
the implementation.

Re: The return value of realloc(p,0)

<WE7zM.474556$GMN3.407254@fx16.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27006&group=comp.lang.c#27006

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx16.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: The return value of realloc(p,0)
Newsgroups: comp.lang.c
References: <ua63if$2u50c$2@news.xmission.com> <DeyxM.134678$ens9.28488@fx45.iad> <86r0ojgvux.fsf@linuxsc.com>
Lines: 37
Message-ID: <WE7zM.474556$GMN3.407254@fx16.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 04 Aug 2023 14:09:58 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 04 Aug 2023 14:09:58 GMT
X-Received-Bytes: 2158
 by: Scott Lurndal - Fri, 4 Aug 2023 14:09 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>Richard Damon <Richard@Damon-Family.org> writes:
>
>> On 7/30/23 12:36 PM, Kenny McCormack wrote:
>>
>>> (On my system) "man realloc" says that:
>>>
>>> If size was equal to 0, either NULL or a pointer suitable to
>>> be passed to free() is returned.
>>>
>>> which is odd, since, although the standard says either one is
>>> legal, the implementation ought to know.
>
>[...]
>
>> As to why the document both behaviors, it may be that they support
>> multiple implementation libraries, and don't want to restrict them
>> more than the Standard does. It is NOT "Impleentation Defined
>> Behavor" as to which it does, it is just Unspecified, so the
>> implementation can do either, and could in fact do both at
>> different times.
>
>The choice for whether an allocation (or reallocation) of size 0
>returns a null pointer or a "unique pointer" has been implementation
>defined since C90: section 7.10.3 paragraph 1 in C90, 7.20.3 p1 in
>n1256 for C99, and 7.22.3 p1 in n1570 for C11.

Even earlier, the System V Interface Definition (SVID3), first published
in 1983, says:

"If the size of the space requested is zero, the bahavior is
implementation defined; the value returned will either be a NULL
pointer or an unique pointer."

The Future Directions section indicates that the interface defintions
will use size_t instead of unsigned for the size parameter and the
older versions were moved to level 2 on 1989-09-30.

Re: The return value of realloc(p,0)

<kl972jF24chU3@mid.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28451&group=comp.lang.c#28451

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: boblat...@yahoo.com (Robert Latest)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: 30 Aug 2023 15:54:59 GMT
Lines: 8
Message-ID: <kl972jF24chU3@mid.individual.net>
References: <ua63if$2u50c$2@news.xmission.com>
<DeyxM.134678$ens9.28488@fx45.iad>
X-Trace: individual.net khD6qKh326EiN3P4tYN+Awl8VHQS+paLTd+hXHDRRbGf3O93Jk
Cancel-Lock: sha1:B6L8X2O6J9Rhj+ny490HBy5Co1o= sha256:wZfgqJyjzsJ2fzfeDKNmQLLJgmUn0boaySvmHHe2yRc=
User-Agent: slrn/1.0.3 (Linux)
 by: Robert Latest - Wed, 30 Aug 2023 15:54 UTC

Richard Damon wrote:
> My understanding is that, in effect, the call to realloc(p,0), if it is
> using the second option of returning a suitable pointer, is effectively
> do a free(p), and then allocating a "0 byte" block of memory and
> returning the address of that.

Or it just returns p, as it might do whenever the requested new size is smaller
than the already-allocated size. No reason for 0 to be a special case.

Re: The return value of realloc(p,0)

<86edjju668.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28477&group=comp.lang.c#28477

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Wed, 30 Aug 2023 22:33:51 -0700
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <86edjju668.fsf@linuxsc.com>
References: <ua63if$2u50c$2@news.xmission.com> <DeyxM.134678$ens9.28488@fx45.iad> <kl972jF24chU3@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="49a0c7fba7d7c0f06cea865d80b29294";
logging-data="3295808"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lkgkhs4+CbtRaynZ5wV26G+QiVQgjw3g="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:GRqX1QNG2qjfvT7yYfDqw0u92ck=
sha1:QG5rLDzdeGRdDRxmzUJ+wm7tRCI=
 by: Tim Rentsch - Thu, 31 Aug 2023 05:33 UTC

Robert Latest <boblatest@yahoo.com> writes:

> Richard Damon wrote:
>
>> My understanding is that, in effect, the call to realloc(p,0), if
>> it is using the second option of returning a suitable pointer, is
>> effectively do a free(p), and then allocating a "0 byte" block of
>> memory and returning the address of that.
>
> Or it just returns p, as it might do whenever the requested new size
> is smaller than the already-allocated size. No reason for 0 to be a
> special case.

There are reasons for realloc() to zize 0 to be a special case.
Specifically, because the pointer value returned doesn't have to
be dereferencable, it can point to parts of the address space
that are otherwise unusable. The overhead for such "zero-byte
blocks" is very low, just a smidge over one bit. The usuable
memory previously allocated can be reclaimed and used in its
entirely for subsequent allocations. If running in a 64-bit
address space, vast amounts of otherwise unusable areas can
be used for these "special objects", having very little impact
on memory usable for actual objects.

Re: The return value of realloc(p,0)

<ucqrn0$3dvle$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28513&group=comp.lang.c#28513

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vir.camp...@invalid.invalid (Vir Campestris)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Thu, 31 Aug 2023 21:03:44 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <ucqrn0$3dvle$1@dont-email.me>
References: <ua63if$2u50c$2@news.xmission.com>
<DeyxM.134678$ens9.28488@fx45.iad> <kl972jF24chU3@mid.individual.net>
<86edjju668.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 31 Aug 2023 20:03:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="64012ee335ecafeb8d167eb95553e90e";
logging-data="3604142"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bEIudIdkeR7FOHreFE5mpPTigjgVkVZg="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:XZjhAutCKV7mf4axc+Zqig8vMD4=
Content-Language: en-GB
In-Reply-To: <86edjju668.fsf@linuxsc.com>
 by: Vir Campestris - Thu, 31 Aug 2023 20:03 UTC

On 31/08/2023 06:33, Tim Rentsch wrote:
> There are reasons for realloc() to zize 0 to be a special case.
> Specifically, because the pointer value returned doesn't have to
> be dereferencable, it can point to parts of the address space
> that are otherwise unusable. The overhead for such "zero-byte
> blocks" is very low, just a smidge over one bit. The usuable
> memory previously allocated can be reclaimed and used in its
> entirely for subsequent allocations. If running in a 64-bit
> address space, vast amounts of otherwise unusable areas can
> be used for these "special objects", having very little impact
> on memory usable for actual objects.

Tim, I'm confused by a little bit of that:

"just a smidge over one bit"

I can see how you might point them all to a single place that can't be
read or written, and have safety in case anyone tries to use them.

I can see that you might have a section of memory with a series of
bytes, each one reserved for these empty allocations. It might be
inaccessible, but will still use address space.

But how do you get anything smaller than a byte, but non-zero? I've only
ever used one CPU with addressing smaller than a byte.

Andy

Re: The return value of realloc(p,0)

<86wmxas6ty.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28539&group=comp.lang.c#28539

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Fri, 01 Sep 2023 00:14:49 -0700
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <86wmxas6ty.fsf@linuxsc.com>
References: <ua63if$2u50c$2@news.xmission.com> <DeyxM.134678$ens9.28488@fx45.iad> <kl972jF24chU3@mid.individual.net> <86edjju668.fsf@linuxsc.com> <ucqrn0$3dvle$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="e13a49a448cc252f76540c1a5198a3b9";
logging-data="3881751"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4P3BVM+AepN3c8jdRIo1lkuz5xJ/xtf4="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:NLQeEX2ldIPinbtq1LvwcE3M8H8=
sha1:64VsRHK8T0w0gSvPLpPX/NldY6E=
 by: Tim Rentsch - Fri, 1 Sep 2023 07:14 UTC

Vir Campestris <vir.campestris@invalid.invalid> writes:

> On 31/08/2023 06:33, Tim Rentsch wrote:
>
>> There are reasons for realloc() to zize 0 to be a special case.
>> Specifically, because the pointer value returned doesn't have to
>> be dereferencable, it can point to parts of the address space
>> that are otherwise unusable. The overhead for such "zero-byte
>> blocks" is very low, just a smidge over one bit. The usuable
>> memory previously allocated can be reclaimed and used in its
>> entirely for subsequent allocations. If running in a 64-bit
>> address space, vast amounts of otherwise unusable areas can
>> be used for these "special objects", having very little impact
>> on memory usable for actual objects.
>
> Tim, I'm confused by a little bit of that:
>
> "just a smidge over one bit"
>
> I can see how you might point them all to a single place that can't be
> read or written, and have safety in case anyone tries to use them.
>
> I can see that you might have a section of memory with a series of
> bytes, each one reserved for these empty allocations. It might be
> inaccessible, but will still use address space.
>
> But how do you get anything smaller than a byte, but non-zero? I've
> only ever used one CPU with addressing smaller than a byte.

I was tempted to make a joke here, but I couldn't see how to turn
out something funny.

What I meant was just over one bit /per zero-byte block/. So if
there were 20,000 zero-byte blocks, they could be managed with
just a little more than 2500 bytes of allocated memory. Sorry
for the confusion.

Re: The return value of realloc(p,0)

<ucsejp$3nrkk$5@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28546&group=comp.lang.c#28546

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vir.camp...@invalid.invalid (Vir Campestris)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Fri, 1 Sep 2023 11:32:25 +0100
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <ucsejp$3nrkk$5@dont-email.me>
References: <ua63if$2u50c$2@news.xmission.com>
<DeyxM.134678$ens9.28488@fx45.iad> <kl972jF24chU3@mid.individual.net>
<86edjju668.fsf@linuxsc.com> <ucqrn0$3dvle$1@dont-email.me>
<86wmxas6ty.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Sep 2023 10:32:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="7263a072cd3654f0dd3422ffc68d0f2d";
logging-data="3927700"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Co2CxF4qLCL/RYiA9QVthw7mQkbhJt6c="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:qhzYdoMU7sWdNUkKrVWfbOwViRA=
In-Reply-To: <86wmxas6ty.fsf@linuxsc.com>
Content-Language: en-GB
 by: Vir Campestris - Fri, 1 Sep 2023 10:32 UTC

On 01/09/2023 08:14, Tim Rentsch wrote:
> Vir Campestris <vir.campestris@invalid.invalid> writes:
>
>> On 31/08/2023 06:33, Tim Rentsch wrote:
>>
>>> There are reasons for realloc() to zize 0 to be a special case.
>>> Specifically, because the pointer value returned doesn't have to
>>> be dereferencable, it can point to parts of the address space
>>> that are otherwise unusable. The overhead for such "zero-byte
>>> blocks" is very low, just a smidge over one bit. The usuable
>>> memory previously allocated can be reclaimed and used in its
>>> entirely for subsequent allocations. If running in a 64-bit
>>> address space, vast amounts of otherwise unusable areas can
>>> be used for these "special objects", having very little impact
>>> on memory usable for actual objects.
>>
>> Tim, I'm confused by a little bit of that:
>>
>> "just a smidge over one bit"
>>
>> I can see how you might point them all to a single place that can't be
>> read or written, and have safety in case anyone tries to use them.
>>
>> I can see that you might have a section of memory with a series of
>> bytes, each one reserved for these empty allocations. It might be
>> inaccessible, but will still use address space.
>>
>> But how do you get anything smaller than a byte, but non-zero? I've
>> only ever used one CPU with addressing smaller than a byte.
>
> I was tempted to make a joke here, but I couldn't see how to turn
> out something funny.
>
> What I meant was just over one bit /per zero-byte block/. So if
> there were 20,000 zero-byte blocks, they could be managed with
> just a little more than 2500 bytes of allocated memory. Sorry
> for the confusion.

I still don't follow you.

If I realloc to size 0 I get an address back. That can be a unique
address, in which case each one uses an address, and therefore a byte.

It can be a shared address, in which case the overhead per allocation is 0.

When I call free it would look at the shared address, and do nothing; if
it's a non-shared address it moves it to a free pool.

What does your bit do?

Andy

Re: The return value of realloc(p,0)

<20230901095453.20@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28564&group=comp.lang.c#28564

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Fri, 1 Sep 2023 17:03:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <20230901095453.20@kylheku.com>
References: <ua63if$2u50c$2@news.xmission.com>
<DeyxM.134678$ens9.28488@fx45.iad> <kl972jF24chU3@mid.individual.net>
<86edjju668.fsf@linuxsc.com> <ucqrn0$3dvle$1@dont-email.me>
<86wmxas6ty.fsf@linuxsc.com>
Injection-Date: Fri, 1 Sep 2023 17:03:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d7d6043c57cccad85a622dc3d680f17e";
logging-data="4141537"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tePOFON8/1M/9aiRpq2nY4lwYrI7z2UU="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:A8PLWy4KenHaZHdpYEtit/M+rA8=
 by: Kaz Kylheku - Fri, 1 Sep 2023 17:03 UTC

On 2023-09-01, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> What I meant was just over one bit /per zero-byte block/. So if
> there were 20,000 zero-byte blocks, they could be managed with
> just a little more than 2500 bytes of allocated memory. Sorry
> for the confusion.

The following is a much better requirement for malloc and realloc:

In the zero size case, return a non-null pointer to a single
program-wide object (always the same one), which can be passed
to the free function any number of times.

Since a zero sized object doesn't store any information, there
is no need to have more than one.

We satisfy these requirements:

- realloc(x, 0) is effectively free(x), except that it also
returns that object.

- the non-null object can be passed to library functions whose
behavior is not defined for null pointers, provided the
functions are not instructed to dereference it, or perform
pointer arithmetic.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: The return value of realloc(p,0)

<20230901100330.31@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28565&group=comp.lang.c#28565

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Fri, 1 Sep 2023 17:08:01 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <20230901100330.31@kylheku.com>
References: <ua63if$2u50c$2@news.xmission.com>
<DeyxM.134678$ens9.28488@fx45.iad> <kl972jF24chU3@mid.individual.net>
<86edjju668.fsf@linuxsc.com> <ucqrn0$3dvle$1@dont-email.me>
<86wmxas6ty.fsf@linuxsc.com> <ucsejp$3nrkk$5@dont-email.me>
Injection-Date: Fri, 1 Sep 2023 17:08:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d7d6043c57cccad85a622dc3d680f17e";
logging-data="4141537"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18n1m7kEJiBETStRTxtpi0E5heBEDT6bS4="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:Xru2dmWaScuoitUmcl+Q0RXdciA=
 by: Kaz Kylheku - Fri, 1 Sep 2023 17:08 UTC

On 2023-09-01, Vir Campestris <vir.campestris@invalid.invalid> wrote:
> It can be a shared address, in which case the overhead per allocation is 0.
>
> When I call free it would look at the shared address, and do nothing; if
> it's a non-shared address it moves it to a free pool.
>
> What does your bit do?

The address returned has to be a unique byte, but it doesn't have to
point to valid virtual or physical memory. On, say, 64 bit systems,
there is a lot of pointer space to play with that will never be used
for storage.

But you have to track, "did we allocate that pointer or not",
which is a Boolean property. That can be packed into a bit array
somewhere, whose elements correspond to a consecutive range of
some pointers. Just like a free sector map in MS-DOS FAT or whatever.

It's a decent implementation of the (possible) protocol that we have in
the standard of allocating unique objects for zero-sized requests.

The protocol itself is a silly idea, though.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: The return value of realloc(p,0)

<uct8mu$3pgff$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28569&group=comp.lang.c#28569

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Fri, 1 Sep 2023 17:57:50 -0000 (UTC)
Organization: The Pitcher Digital Freehold
Lines: 40
Message-ID: <uct8mu$3pgff$1@dont-email.me>
References: <ua63if$2u50c$2@news.xmission.com>
<DeyxM.134678$ens9.28488@fx45.iad> <kl972jF24chU3@mid.individual.net>
<86edjju668.fsf@linuxsc.com> <ucqrn0$3dvle$1@dont-email.me>
<86wmxas6ty.fsf@linuxsc.com> <20230901095453.20@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 1 Sep 2023 17:57:50 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="54dd6ff3c5151f08421ab5417076d737";
logging-data="3981807"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/L4y9gKWzElnbIbFG2YUfyCb409cgNWhY="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:McEhL9P/vpctXKxrfHZIpO+wmgc=
 by: Lew Pitcher - Fri, 1 Sep 2023 17:57 UTC

On Fri, 01 Sep 2023 17:03:06 +0000, Kaz Kylheku wrote:

> On 2023-09-01, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>> What I meant was just over one bit /per zero-byte block/. So if there
>> were 20,000 zero-byte blocks, they could be managed with just a little
>> more than 2500 bytes of allocated memory. Sorry for the confusion.
>
> The following is a much better requirement for malloc and realloc:
>
> In the zero size case, return a non-null pointer to a single
> program-wide object (always the same one), which can be passed to the
> free function any number of times.
>
> Since a zero sized object doesn't store any information, there is no
> need to have more than one.
>
> We satisfy these requirements:
>
> - realloc(x, 0) is effectively free(x), except that it also
> returns that object.
>
> - the non-null object can be passed to library functions whose
> behavior is not defined for null pointers, provided the functions are
> not instructed to dereference it, or perform pointer arithmetic.

This last point implies that there must be some way for code to
distinguish this non-null object (that cannot be dereferenced)
from other non-null objects that /can/ be dereferenced.

Given that you specify that the non-null pointer returned from
realloc(x,0)
would be "a single program-wide object" and "always the same one",
would you consider providing a unique name (like we do for the
null pointer constant NULL) for such an object? If so, what name
would you suggest, and what would the definition look like?

Just curious,
--
Lew Pitcher
"In Skills We Trust"

Re: The return value of realloc(p,0)

<86sf7xspk3.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28577&group=comp.lang.c#28577

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Fri, 01 Sep 2023 11:42:36 -0700
Organization: A noiseless patient Spider
Lines: 78
Message-ID: <86sf7xspk3.fsf@linuxsc.com>
References: <ua63if$2u50c$2@news.xmission.com> <DeyxM.134678$ens9.28488@fx45.iad> <kl972jF24chU3@mid.individual.net> <86edjju668.fsf@linuxsc.com> <ucqrn0$3dvle$1@dont-email.me> <86wmxas6ty.fsf@linuxsc.com> <ucsejp$3nrkk$5@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="e13a49a448cc252f76540c1a5198a3b9";
logging-data="4175704"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/zokdnKEnWVmvU6tZy+dy7c2pObwsMivA="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:qVwPFGr8Kz4eK/WDdEScCkcDHA0=
sha1:8tTVocXtpMtb2ZF60t68spNMgPw=
 by: Tim Rentsch - Fri, 1 Sep 2023 18:42 UTC

Vir Campestris <vir.campestris@invalid.invalid> writes:

> On 01/09/2023 08:14, Tim Rentsch wrote:
>
>> Vir Campestris <vir.campestris@invalid.invalid> writes:
>>
>>> On 31/08/2023 06:33, Tim Rentsch wrote:
>>>
>>>> There are reasons for realloc() to zize 0 to be a special case.
>>>> Specifically, because the pointer value returned doesn't have to
>>>> be dereferencable, it can point to parts of the address space
>>>> that are otherwise unusable. The overhead for such "zero-byte
>>>> blocks" is very low, just a smidge over one bit. The usuable
>>>> memory previously allocated can be reclaimed and used in its
>>>> entirely for subsequent allocations. If running in a 64-bit
>>>> address space, vast amounts of otherwise unusable areas can
>>>> be used for these "special objects", having very little impact
>>>> on memory usable for actual objects.
>>>
>>> Tim, I'm confused by a little bit of that:
>>>
>>> "just a smidge over one bit"
>>>
>>> I can see how you might point them all to a single place that can't be
>>> read or written, and have safety in case anyone tries to use them.
>>>
>>> I can see that you might have a section of memory with a series of
>>> bytes, each one reserved for these empty allocations. It might be
>>> inaccessible, but will still use address space.
>>>
>>> But how do you get anything smaller than a byte, but non-zero? I've
>>> only ever used one CPU with addressing smaller than a byte.
>>
>> I was tempted to make a joke here, but I couldn't see how to turn
>> out something funny.
>>
>> What I meant was just over one bit /per zero-byte block/. So if
>> there were 20,000 zero-byte blocks, they could be managed with
>> just a little more than 2500 bytes of allocated memory. Sorry
>> for the confusion.
>
> I still don't follow you.
>
> If I realloc to size 0 I get an address back. That can be a unique
> address, in which case each one uses an address, and therefore a byte.
> [...]

In fact it must be a unique address, distinct from any other
address that has been allocated but not yet freed.

The key point is that, when the size is zero, the allocation
routine allocates /address space/ but does not allocate /memory/.
The address is not mapped to any memory, either physical or
virtual.

In a 64-bit address space, there are a lot more addresses than
there are bytes of memory, even virtual bytes of memory. All but
a very small fraction of 64-bit addresses cannot map to actual
memory, because there is no room on the address bus (figuratively
speaking).

For example, suppose our zero byte block reside at addresses
in the range

0x800000000000 to
0x802000000000

and "objects" are aligned to 32-byte boundaries. That means
there are 4294967296 zero-byte "objects" available. For each of
those objects, we need to know if it has been allocated by not
yet freed, that is, one bit per object. Add in a few extra
pointers and counts to manage the space to hold the bitmap
(so we don't have to use much more space for the bitmap than
is necessary), and we get a little over one bit /of actual
memory/ that is used to manage the zero-byte objects, which
take no actual memory.

Does that make more sense now?

Re: The return value of realloc(p,0)

<20230901113229.84@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28578&group=comp.lang.c#28578

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Fri, 1 Sep 2023 18:44:55 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 98
Message-ID: <20230901113229.84@kylheku.com>
References: <ua63if$2u50c$2@news.xmission.com>
<DeyxM.134678$ens9.28488@fx45.iad> <kl972jF24chU3@mid.individual.net>
<86edjju668.fsf@linuxsc.com> <ucqrn0$3dvle$1@dont-email.me>
<86wmxas6ty.fsf@linuxsc.com> <20230901095453.20@kylheku.com>
<uct8mu$3pgff$1@dont-email.me>
Injection-Date: Fri, 1 Sep 2023 18:44:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d7d6043c57cccad85a622dc3d680f17e";
logging-data="4176411"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xvGdstWWuN5D6jlYCudkYFCGTCVpv7cI="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:yf+HE/hRZoAFTkA+Yt8oFYZBF5I=
 by: Kaz Kylheku - Fri, 1 Sep 2023 18:44 UTC

On 2023-09-01, Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
> On Fri, 01 Sep 2023 17:03:06 +0000, Kaz Kylheku wrote:
>
>> On 2023-09-01, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>>> What I meant was just over one bit /per zero-byte block/. So if there
>>> were 20,000 zero-byte blocks, they could be managed with just a little
>>> more than 2500 bytes of allocated memory. Sorry for the confusion.
>>
>> The following is a much better requirement for malloc and realloc:
>>
>> In the zero size case, return a non-null pointer to a single
>> program-wide object (always the same one), which can be passed to the
>> free function any number of times.
>>
>> Since a zero sized object doesn't store any information, there is no
>> need to have more than one.
>>
>> We satisfy these requirements:
>>
>> - realloc(x, 0) is effectively free(x), except that it also
>> returns that object.
>>
>> - the non-null object can be passed to library functions whose
>> behavior is not defined for null pointers, provided the functions are
>> not instructed to dereference it, or perform pointer arithmetic.
>
> This last point implies that there must be some way for code to
> distinguish this non-null object (that cannot be dereferenced)
> from other non-null objects that /can/ be dereferenced.

No, it doesn't.

Say we make this pointer:

char x[4], *p = x + 4;

f(p);

p effectively points to the base of a zero length array: one
byte past its last element.

Does f need "some what to distinguish this p value from one that
can bedereferenced"?
>
> Given that you specify that the non-null pointer returned from
> realloc(x,0)
> would be "a single program-wide object" and "always the same one",
> would you consider providing a unique name (like we do for the
> null pointer constant NULL) for such an object?

Tentatively yes. POSIX systems could use the same value as MAP_FAILED
which is typically

#define MAP_FAILED ((void *) -1)

It is sometimes useful to have an additional pointer value that is
not the same as any object, and invalid.

One example is in this source file:

https://www.kylheku.com/cgit/txr/tree/regex.c

Look for casts like coerce(cset_L2_t *, -1). I didn't define
a constant for this.

This code implements a multi-level radix tree structure for
representing Unicode character sets.

A null pointer at any level in the tree indicates that that
section of the space is all zero bits: those code points
under that tree are not in the set. We don't have to allocate
the underying directories and pages just to fill them wit zeros.

I also wanted an efficient way to say that an entire subtree
contains nothing but 1 bits. For that, I used a -1 converted
to the pointer type.

> If so, what name
> would you suggest, and what would the definition look like?

The definition cannot be dictated at the ISO C level;
only its properties can be described.

In some implementation ((void *) -1) might be indistinguishable
from the null pointer; you know the deal.

I'm not conviced that the constant would have to be published just for
the purpose of its connection with malloc(0); it would have to be
considered separately useful.

And even then, it would ahve to be decided whether that constant should
actually be that malloc(0) value, or should that still use its own
value.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: The return value of realloc(p,0)

<86fs3xsoyq.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28583&group=comp.lang.c#28583

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Fri, 01 Sep 2023 11:55:25 -0700
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <86fs3xsoyq.fsf@linuxsc.com>
References: <ua63if$2u50c$2@news.xmission.com> <DeyxM.134678$ens9.28488@fx45.iad> <kl972jF24chU3@mid.individual.net> <86edjju668.fsf@linuxsc.com> <ucqrn0$3dvle$1@dont-email.me> <86wmxas6ty.fsf@linuxsc.com> <20230901095453.20@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="e13a49a448cc252f76540c1a5198a3b9";
logging-data="4175704"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PimG4WLYpJPUkt7FmAG5eL4NAVneYsRA="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:+P6KHiFINnu/zLvc9/O3LZI0ipE=
sha1:SYI/Chc11ybKVh8mrBe2mWrv4pQ=
 by: Tim Rentsch - Fri, 1 Sep 2023 18:55 UTC

Kaz Kylheku <864-117-4973@kylheku.com> writes:

> On 2023-09-01, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>
>> What I meant was just over one bit /per zero-byte block/. So if
>> there were 20,000 zero-byte blocks, they could be managed with
>> just a little more than 2500 bytes of allocated memory. Sorry
>> for the confusion.
>
> The following is a much better requirement for malloc and realloc:
>
> In the zero size case, return a non-null pointer to a single
> program-wide object (always the same one), which can be passed
> to the free function any number of times. [...]

This idea is worse in one important respect: it doesn't satisfy
the specification in the C standard.

Incidentally, it also doesn't satisfy the requirements of the
people who proposed the idea to begin with.

Re: The return value of realloc(p,0)

<86bkelsou0.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28585&group=comp.lang.c#28585

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Fri, 01 Sep 2023 11:58:15 -0700
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <86bkelsou0.fsf@linuxsc.com>
References: <ua63if$2u50c$2@news.xmission.com> <DeyxM.134678$ens9.28488@fx45.iad> <kl972jF24chU3@mid.individual.net> <86edjju668.fsf@linuxsc.com> <ucqrn0$3dvle$1@dont-email.me> <86wmxas6ty.fsf@linuxsc.com> <20230901095453.20@kylheku.com> <uct8mu$3pgff$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="e13a49a448cc252f76540c1a5198a3b9";
logging-data="4175704"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+uIUZ980b6N7wGGdKNQRa68eCDefBaubg="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:q1Pbz7U7qgO4O2ZECFQSuRxjMIs=
sha1:0y87pZJm0ryR0dFGyXmyKLHh2qg=
 by: Tim Rentsch - Fri, 1 Sep 2023 18:58 UTC

Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:

> On Fri, 01 Sep 2023 17:03:06 +0000, Kaz Kylheku wrote:
>
>> On 2023-09-01, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>>
>>> What I meant was just over one bit /per zero-byte block/. So if there
>>> were 20,000 zero-byte blocks, they could be managed with just a little
>>> more than 2500 bytes of allocated memory. Sorry for the confusion.
>>
>> The following is a much better requirement for malloc and realloc:
>>
>> In the zero size case, return a non-null pointer to a single
>> program-wide object (always the same one), which can be passed to the
>> free function any number of times.
>>
>> Since a zero sized object doesn't store any information, there is no
>> need to have more than one.
>>
>> We satisfy these requirements:
>>
>> - realloc(x, 0) is effectively free(x), except that it also
>> returns that object.
>>
>> - the non-null object can be passed to library functions whose
>> behavior is not defined for null pointers, provided the functions are
>> not instructed to dereference it, or perform pointer arithmetic.
>
> This last point implies that there must be some way for code to
> distinguish this non-null object (that cannot be dereferenced)
> from other non-null objects that /can/ be dereferenced.

The idea that zero-byte objects can all be the same doesn't
satisfy the specifications in the C standard.

Re: The return value of realloc(p,0)

<JCqIM.79177$m8Ke.22576@fx08.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28588&group=comp.lang.c#28588

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx08.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: The return value of realloc(p,0)
Newsgroups: comp.lang.c
References: <ua63if$2u50c$2@news.xmission.com> <DeyxM.134678$ens9.28488@fx45.iad> <kl972jF24chU3@mid.individual.net> <86edjju668.fsf@linuxsc.com> <ucqrn0$3dvle$1@dont-email.me> <86wmxas6ty.fsf@linuxsc.com> <ucsejp$3nrkk$5@dont-email.me> <86sf7xspk3.fsf@linuxsc.com>
Lines: 25
Message-ID: <JCqIM.79177$m8Ke.22576@fx08.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 01 Sep 2023 19:06:17 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 01 Sep 2023 19:06:17 GMT
X-Received-Bytes: 1816
 by: Scott Lurndal - Fri, 1 Sep 2023 19:06 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>Vir Campestris <vir.campestris@invalid.invalid> writes:
>
>
>In a 64-bit address space, there are a lot more addresses than
>there are bytes of memory, even virtual bytes of memory. All but
>a very small fraction of 64-bit addresses cannot map to actual
>memory, because there is no room on the address bus (figuratively
>speaking).

Current processors support between 44 and 52 bits of physical
address, and for the most part, the same on the virtual address
space as well. ARMv8 allows the VA space to be anywhere
from 16 bits to 52 bits on a per-translation-context) basis;
where smaller VA sizes can significantly decrease translation
table walk cost (i.e. by skipping levels).

With DDR5 and HBM we're seeing terabytes of DRAM on the bus.

With CXL (and Intel's PUMA chip) the physical address bus
will be fully utilized (all 64 bits) in the not so distant
future, if perhaps sparsely by using higher order bits to
identify nodes on the fabric.

Re: The return value of realloc(p,0)

<20230901120930.698@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28589&group=comp.lang.c#28589

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Fri, 1 Sep 2023 19:14:28 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <20230901120930.698@kylheku.com>
References: <ua63if$2u50c$2@news.xmission.com>
<DeyxM.134678$ens9.28488@fx45.iad> <kl972jF24chU3@mid.individual.net>
<86edjju668.fsf@linuxsc.com> <ucqrn0$3dvle$1@dont-email.me>
<86wmxas6ty.fsf@linuxsc.com> <20230901095453.20@kylheku.com>
<uct8mu$3pgff$1@dont-email.me> <86bkelsou0.fsf@linuxsc.com>
Injection-Date: Fri, 1 Sep 2023 19:14:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d7d6043c57cccad85a622dc3d680f17e";
logging-data="4187119"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18c8O3HYTkiJnud4peV7xA6tsMITm22q5o="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:zob/e9MrwXc+3nx7cAw9KQsRSpM=
 by: Kaz Kylheku - Fri, 1 Sep 2023 19:14 UTC

On 2023-09-01, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> The idea that zero-byte objects can all be the same doesn't
> satisfy the specifications in the C standard.

yes; we all know are talking about an alternative requiremnt
that is not one of the current two implementation-defined choices.

However, anyone can implement the idea (or others) in an allocator
wrapper.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor