Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

New systems generate new problems.


devel / comp.lang.c / Re: 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
Re: The return value of realloc(p,0)

<uctham$3pgff$2@dont-email.me>

  copy mid

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

  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 20:24:54 -0000 (UTC)
Organization: The Pitcher Digital Freehold
Lines: 72
Message-ID: <uctham$3pgff$2@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>
<uct8mu$3pgff$1@dont-email.me> <20230901113229.84@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 1 Sep 2023 20:24:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="54dd6ff3c5151f08421ab5417076d737";
logging-data="3981807"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195DMCw1mtNkBHbgcFz60mPNkEViEq0h4Y="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:ePkD7xoqYlw6Li+ZP0aHgINCAWE=
 by: Lew Pitcher - Fri, 1 Sep 2023 20:24 UTC

On Fri, 01 Sep 2023 18:44:55 +0000, Kaz Kylheku wrote:

> 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
> be dereferenced"?

OK, I get that. I took your statement that "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" as implying that, for instance
strcpy(realloc(x,0),"abc"); /* unrealistic, but... */
would need some way to determine that the function would need to check
the given destination pointer for it's zero-length not-nullness before
performing the requested copy operation. If it does not, then the
standard function would violate your "cannot be dereferenced or be the
subject of pointer arithmetic" rule.

So, I guess that strcpy() will just have to "take it on faith" that
the given pointer points to something of more than zero size.

ISTM that strcpy() can easily test it's arguments for NULLness and
cleanly abort the copy operation if either equals NULL, although it is
under no obligation to do so by the C standard. I wondered how the
function could ensure that neither of it's arguments were of the
not-null zero-length variety.

Thanks for the clarification.
--
Lew Pitcher
"In Skills We Trust"

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

<ud06jv$hibn$4@dont-email.me>

  copy mid

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

  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: Sat, 2 Sep 2023 21:40:30 +0100
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <ud06jv$hibn$4@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> <ucsejp$3nrkk$5@dont-email.me>
<86sf7xspk3.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 2 Sep 2023 20:40:31 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="71f880443bfc728e6c9e8e2ede404518";
logging-data="575863"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18xORxTJjDGFFpavsdjAHqb/G6M03fN32g="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:Xrm+NGe+yx2CIAWq+quT0uz+YQ0=
Content-Language: en-GB
In-Reply-To: <86sf7xspk3.fsf@linuxsc.com>
 by: Vir Campestris - Sat, 2 Sep 2023 20:40 UTC

On 01/09/2023 19:42, Tim Rentsch wrote:
> 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?

Yes, it does. Thank you (and Kaz).

Andy

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

<86zg23r6fi.fsf@linuxsc.com>

  copy mid

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

  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: Sun, 03 Sep 2023 01:45:37 -0700
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <86zg23r6fi.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> <86sf7xspk3.fsf@linuxsc.com> <JCqIM.79177$m8Ke.22576@fx08.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="6ef63087f855104b64afdd13e03f4862";
logging-data="896175"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/SfRkZuoqIr9Em1UU9YMb/t57o2x8ddQs="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:B7/rSy2v2WAM3dnLtpNAhxt8OOg=
sha1:/h23ah9qHIBgkyXFaW2Ao8kE3nE=
 by: Tim Rentsch - Sun, 3 Sep 2023 08:45 UTC

scott@slp53.sl.home (Scott Lurndal) writes:

> 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.

Still plenty of address space left over.

> 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.

I think the key word there is sparsely. A very small
fraction of a 64-bit address space suffices, and that
needn't be all contiguous either - it's easy to handle
a modest number of distinct areas, without too much
burden either in space or time.

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

<0g2JM.580001$U3w1.358152@fx09.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx09.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> <JCqIM.79177$m8Ke.22576@fx08.iad> <86zg23r6fi.fsf@linuxsc.com>
Lines: 43
Message-ID: <0g2JM.580001$U3w1.358152@fx09.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sun, 03 Sep 2023 16:12:44 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sun, 03 Sep 2023 16:12:44 GMT
X-Received-Bytes: 2699
 by: Scott Lurndal - Sun, 3 Sep 2023 16:12 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>scott@slp53.sl.home (Scott Lurndal) writes:
>
>> 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.
>
>Still plenty of address space left over.
>
>> 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.
>
>I think the key word there is sparsely. A very small
>fraction of a 64-bit address space suffices, and that
>needn't be all contiguous either - it's easy to handle
>a modest number of distinct areas, without too much
>burden either in space or time.

Perhaps, but vis-a-vis realloc(p,0), I'd say just don't
do that rather than adding an arcane 'zero-byte object'
concept. Deprecate the feature completely.

In fact, I'd suggest using malloc(), memcpy()/and free() if
necessary to reallocate something.

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

<86a5u3qdwt.fsf@linuxsc.com>

  copy mid

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

  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: Sun, 03 Sep 2023 12:01:38 -0700
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <86a5u3qdwt.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> <86sf7xspk3.fsf@linuxsc.com> <JCqIM.79177$m8Ke.22576@fx08.iad> <86zg23r6fi.fsf@linuxsc.com> <0g2JM.580001$U3w1.358152@fx09.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="6ef63087f855104b64afdd13e03f4862";
logging-data="1104452"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hpaZWy46Kzxj2ZLfloKR7CQGVEQnM1oI="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:PtEsU9GArRgY3r1jJmkR1Y+PrQ8=
sha1:JebZ8jZX9ybyZ/yYwQcut2bwPkY=
 by: Tim Rentsch - Sun, 3 Sep 2023 19:01 UTC

scott@slp53.sl.home (Scott Lurndal) writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

[use of address space for zero-byte allocated objects]

>> I think the key word there is sparsely. A very small
>> fraction of a 64-bit address space suffices, and that
>> needn't be all contiguous either - it's easy to handle
>> a modest number of distinct areas, without too much
>> burden either in space or time.
>
> Perhaps, but vis-a-vis realloc(p,0), I'd say just don't
> do that rather than adding an arcane 'zero-byte object'
> concept. Deprecate the feature completely.

Probably a lot of other people agree with you, but the problem
is not just realloc(). A call of malloc(0) has the same problem.
And that problem is not going away - the C standard gives an
implementation-defined choice as to whether malloc(0) returns
NULL or a pointer to "a zero-sized object" (my phrasing).

> In fact, I'd suggest using malloc(), memcpy()/and free() if
> necessary to reallocate something.

I think that idea is nutty. The realloc() function serves a
useful purpose, including better utilization of memory. If
someone wants to avoid the weird possibilities of zero-sized
objects, it's easy enough to program around that without
having to completely give up on realloc().

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

<865y4rqdu3.fsf@linuxsc.com>

  copy mid

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

  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: Sun, 03 Sep 2023 12:03:16 -0700
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <865y4rqdu3.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> <86bkelsou0.fsf@linuxsc.com> <20230901120930.698@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="6ef63087f855104b64afdd13e03f4862";
logging-data="1104452"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hYFdjCBkuNHNbP5kvdbDIjf0Sv+kLWX4="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:7/abk/99VyplclX+zrANXsvRX1M=
sha1:lKEZSc1jJxLVdR+yhsUrUn/cETI=
 by: Tim Rentsch - Sun, 3 Sep 2023 19:03 UTC

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

> 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.

Yes, anyone can, but no one does, because it's a lame idea.

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

<w37JM.963104$TPw2.634145@fx17.iad>

  copy mid

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

  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!fx17.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> <JCqIM.79177$m8Ke.22576@fx08.iad> <86zg23r6fi.fsf@linuxsc.com> <0g2JM.580001$U3w1.358152@fx09.iad> <86a5u3qdwt.fsf@linuxsc.com>
Lines: 42
Message-ID: <w37JM.963104$TPw2.634145@fx17.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sun, 03 Sep 2023 21:40:44 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sun, 03 Sep 2023 21:40:44 GMT
X-Received-Bytes: 2778
 by: Scott Lurndal - Sun, 3 Sep 2023 21:40 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>scott@slp53.sl.home (Scott Lurndal) writes:
>
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>[use of address space for zero-byte allocated objects]
>
>>> I think the key word there is sparsely. A very small
>>> fraction of a 64-bit address space suffices, and that
>>> needn't be all contiguous either - it's easy to handle
>>> a modest number of distinct areas, without too much
>>> burden either in space or time.
>>
>> Perhaps, but vis-a-vis realloc(p,0), I'd say just don't
>> do that rather than adding an arcane 'zero-byte object'
>> concept. Deprecate the feature completely.
>
>Probably a lot of other people agree with you, but the problem
>is not just realloc(). A call of malloc(0) has the same problem.
>And that problem is not going away - the C standard gives an
>implementation-defined choice as to whether malloc(0) returns
>NULL or a pointer to "a zero-sized object" (my phrasing).
>
>> In fact, I'd suggest using malloc(), memcpy()/and free() if
>> necessary to reallocate something.
>
>I think that idea is nutty. The realloc() function serves a
>useful purpose, including better utilization of memory. If
>someone wants to avoid the weird possibilities of zero-sized
>objects, it's easy enough to program around that without
>having to completely give up on realloc().

I've never used it (realloc) in forty-plus years of C programming.

As for better utilization of memory, there may be cases where
a growth request can be fulfilled by expanding the existing
allocation (e.g. glibc _int_realloc). I'd think that would be
less likely in modern threaded environments, although I'd like
to see some real workload data, perhaps by instrumenting
_int_realloc to keep statistics on the frequency of cases
where the memcpy is not required.

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

<Pe98Ajw9UVrFjjOKy@bongo-ra.co>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.c
Subject: Re: The return value of realloc(p,0)
Date: Sun, 3 Sep 2023 23:08:33 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 5
Message-ID: <Pe98Ajw9UVrFjjOKy@bongo-ra.co>
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> <JCqIM.79177$m8Ke.22576@fx08.iad>
<86zg23r6fi.fsf@linuxsc.com> <0g2JM.580001$U3w1.358152@fx09.iad> <86a5u3qdwt.fsf@linuxsc.com>
<w37JM.963104$TPw2.634145@fx17.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 3 Sep 2023 23:08:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="14c909e5e0bb391cf5e3b9e4113bca6b";
logging-data="1179422"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/sB72fmiirGFOOjShNWApD"
Cancel-Lock: sha1:U/cZiDVb8BYfThWBZyuVwXJpGc4=
In-Reply-To: <w37JM.963104$TPw2.634145@fx17.iad>
X-Organisation: Weyland-Yutani
X-Server-Commands: nowebcancel
 by: Spiros Bousbouras - Sun, 3 Sep 2023 23:08 UTC

On Sun, 03 Sep 2023 21:40:44 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
> I've never used it (realloc) in forty-plus years of C programming.

I use it all the time.

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

<8b386575-5e87-4784-ab0a-a6530acbd500n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1805:b0:40f:e2a5:3100 with SMTP id t5-20020a05622a180500b0040fe2a53100mr291237qtc.6.1693783430722;
Sun, 03 Sep 2023 16:23:50 -0700 (PDT)
X-Received: by 2002:a17:903:2309:b0:1c1:fbec:bc39 with SMTP id
d9-20020a170903230900b001c1fbecbc39mr3139431plh.4.1693783430429; Sun, 03 Sep
2023 16:23:50 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 3 Sep 2023 16:23:49 -0700 (PDT)
In-Reply-To: <Pe98Ajw9UVrFjjOKy@bongo-ra.co>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:d1a7:af75:4963:9499;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:d1a7:af75:4963:9499
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>
<JCqIM.79177$m8Ke.22576@fx08.iad> <86zg23r6fi.fsf@linuxsc.com>
<0g2JM.580001$U3w1.358152@fx09.iad> <86a5u3qdwt.fsf@linuxsc.com>
<w37JM.963104$TPw2.634145@fx17.iad> <Pe98Ajw9UVrFjjOKy@bongo-ra.co>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8b386575-5e87-4784-ab0a-a6530acbd500n@googlegroups.com>
Subject: Re: The return value of realloc(p,0)
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Sun, 03 Sep 2023 23:23:50 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Malcolm McLean - Sun, 3 Sep 2023 23:23 UTC

On Monday, 4 September 2023 at 00:08:47 UTC+1, Spiros Bousbouras wrote:
> On Sun, 03 Sep 2023 21:40:44 GMT
> sc...@slp53.sl.home (Scott Lurndal) wrote:
> > I've never used it (realloc) in forty-plus years of C programming.
> I use it all the time.
>
It's used heavily for data input where the data comes in a stream with a sentinel
indicating end of data. Particularly if the stream cannot be guaranteed seekable.

It's seldom needed for core algorithms, because normally there's a fairly tight upper
bound on the memory space required.

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

<86sf7uq01g.fsf@linuxsc.com>

  copy mid

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

  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: Sun, 03 Sep 2023 17:01:15 -0700
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <86sf7uq01g.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> <86sf7xspk3.fsf@linuxsc.com> <JCqIM.79177$m8Ke.22576@fx08.iad> <86zg23r6fi.fsf@linuxsc.com> <0g2JM.580001$U3w1.358152@fx09.iad> <86a5u3qdwt.fsf@linuxsc.com> <w37JM.963104$TPw2.634145@fx17.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="e731bbb82483d3b3451e3d39a3921e01";
logging-data="1191843"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198eH11kFjXpcKhHhmb+rWVaMZFpBPCH7o="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:vxLBsQuajYLlxfhN1xLiX3aGAJ8=
sha1:kVMvytBygtKx+rgnHGPdjQjNEyY=
 by: Tim Rentsch - Mon, 4 Sep 2023 00:01 UTC

scott@slp53.sl.home (Scott Lurndal) writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> scott@slp53.sl.home (Scott Lurndal) writes:
>>
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>
>> [use of address space for zero-byte allocated objects]
>>
>>>> I think the key word there is sparsely. A very small
>>>> fraction of a 64-bit address space suffices, and that
>>>> needn't be all contiguous either - it's easy to handle
>>>> a modest number of distinct areas, without too much
>>>> burden either in space or time.
>>>
>>> Perhaps, but vis-a-vis realloc(p,0), I'd say just don't
>>> do that rather than adding an arcane 'zero-byte object'
>>> concept. Deprecate the feature completely.
>>
>> Probably a lot of other people agree with you, but the problem
>> is not just realloc(). A call of malloc(0) has the same problem.
>> And that problem is not going away - the C standard gives an
>> implementation-defined choice as to whether malloc(0) returns
>> NULL or a pointer to "a zero-sized object" (my phrasing).
>>
>>> In fact, I'd suggest using malloc(), memcpy()/and free() if
>>> necessary to reallocate something.
>>
>> I think that idea is nutty. The realloc() function serves a
>> useful purpose, including better utilization of memory. If
>> someone wants to avoid the weird possibilities of zero-sized
>> objects, it's easy enough to program around that without
>> having to completely give up on realloc().
>
> I've never used it (realloc) in forty-plus years of C programming.
>
> As for better utilization of memory, there may be cases where
> a growth request can be fulfilled by expanding the existing
> allocation (e.g. glibc _int_realloc). I'd think that would be
> less likely in modern threaded environments, although I'd like
> to see some real workload data, perhaps by instrumenting
> _int_realloc to keep statistics on the frequency of cases
> where the memcpy is not required.

Obviously it depends on how much memory is available, and how
close to the memory limits the program is running. If we have an
environment with only, say, 1.5 G available, and we want to grow
a 0.8 G block to 1 G, the malloc/copy/free approach will fail,
but using realloc may very well succeed. Even shrinking a memory
block can fail under the malloc/copy/free approach, but will
almost certainly succeed when using realloc. Clearly there are
some potential upsides to using realloc, and I don't see any
downsides. So I still don't understand your position, unless
you're saying this is what you've always done and you don't see
any reason to change it, even if it might be suboptimal.

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

<RKlJM.780912$mPI2.44757@fx15.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx15.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> <JCqIM.79177$m8Ke.22576@fx08.iad> <86zg23r6fi.fsf@linuxsc.com> <0g2JM.580001$U3w1.358152@fx09.iad> <86a5u3qdwt.fsf@linuxsc.com> <w37JM.963104$TPw2.634145@fx17.iad> <86sf7uq01g.fsf@linuxsc.com>
Lines: 65
Message-ID: <RKlJM.780912$mPI2.44757@fx15.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 04 Sep 2023 14:22:41 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 04 Sep 2023 14:22:41 GMT
X-Received-Bytes: 4140
 by: Scott Lurndal - Mon, 4 Sep 2023 14:22 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>scott@slp53.sl.home (Scott Lurndal) writes:
>
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>
>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>
>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>
>>> [use of address space for zero-byte allocated objects]
>>>
>>>>> I think the key word there is sparsely. A very small
>>>>> fraction of a 64-bit address space suffices, and that
>>>>> needn't be all contiguous either - it's easy to handle
>>>>> a modest number of distinct areas, without too much
>>>>> burden either in space or time.
>>>>
>>>> Perhaps, but vis-a-vis realloc(p,0), I'd say just don't
>>>> do that rather than adding an arcane 'zero-byte object'
>>>> concept. Deprecate the feature completely.
>>>
>>> Probably a lot of other people agree with you, but the problem
>>> is not just realloc(). A call of malloc(0) has the same problem.
>>> And that problem is not going away - the C standard gives an
>>> implementation-defined choice as to whether malloc(0) returns
>>> NULL or a pointer to "a zero-sized object" (my phrasing).
>>>
>>>> In fact, I'd suggest using malloc(), memcpy()/and free() if
>>>> necessary to reallocate something.
>>>
>>> I think that idea is nutty. The realloc() function serves a
>>> useful purpose, including better utilization of memory. If
>>> someone wants to avoid the weird possibilities of zero-sized
>>> objects, it's easy enough to program around that without
>>> having to completely give up on realloc().
>>
>> I've never used it (realloc) in forty-plus years of C programming.
>>
>> As for better utilization of memory, there may be cases where
>> a growth request can be fulfilled by expanding the existing
>> allocation (e.g. glibc _int_realloc). I'd think that would be
>> less likely in modern threaded environments, although I'd like
>> to see some real workload data, perhaps by instrumenting
>> _int_realloc to keep statistics on the frequency of cases
>> where the memcpy is not required.
>
>Obviously it depends on how much memory is available, and how
>close to the memory limits the program is running. If we have an
>environment with only, say, 1.5 G available, and we want to grow
>a 0.8 G block to 1 G, the malloc/copy/free approach will fail,
>but using realloc may very well succeed. Even shrinking a memory
>block can fail under the malloc/copy/free approach, but will
>almost certainly succeed when using realloc. Clearly there are
>some potential upsides to using realloc, and I don't see any
>downsides. So I still don't understand your position, unless
>you're saying this is what you've always done and you don't see
>any reason to change it, even if it might be suboptimal.

Most of the code I've worked on has been bare metal (operating systems,
hypervisors, run-time firmware) where dynamic allocation is
either discouraged or managed with fixed size pool allocators or
slab allocators, et cetera. I suppose that's influenced my thinking about
the desirability of realloc() and run-time heap management.

Clearly others have found it useful.

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

<ud4tqb$1h5ng$4@dont-email.me>

  copy mid

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

  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: Mon, 4 Sep 2023 16:40:59 +0100
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <ud4tqb$1h5ng$4@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> <ucsejp$3nrkk$5@dont-email.me>
<86sf7xspk3.fsf@linuxsc.com> <JCqIM.79177$m8Ke.22576@fx08.iad>
<86zg23r6fi.fsf@linuxsc.com> <0g2JM.580001$U3w1.358152@fx09.iad>
<86a5u3qdwt.fsf@linuxsc.com> <w37JM.963104$TPw2.634145@fx17.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 4 Sep 2023 15:40:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="852649fb83ca7e885db61a42e853a290";
logging-data="1611504"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+l/0jtRDsUlqPDcJ3qv7Nc9w/Bpwr6ptA="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:+A/9jwZy0FLhNrUxbeQrT8tHv5M=
In-Reply-To: <w37JM.963104$TPw2.634145@fx17.iad>
Content-Language: en-GB
 by: Vir Campestris - Mon, 4 Sep 2023 15:40 UTC

On 03/09/2023 22:40, Scott Lurndal wrote:
> I've never used it (realloc) in forty-plus years of C programming.
>
> As for better utilization of memory, there may be cases where
> a growth request can be fulfilled by expanding the existing
> allocation (e.g. glibc _int_realloc). I'd think that would be
> less likely in modern threaded environments, although I'd like
> to see some real workload data, perhaps by instrumenting
> _int_realloc to keep statistics on the frequency of cases
> where the memcpy is not required.

If I have a block of memory, and I want to change its size, it's
possible that the heap management routines can optimise to something
better than make new allocation then memcpy. Perhaps there's enough free
space just past my buffer for my expansion. Perhaps there's enough free
memory that it's not worth moving the data to a smaller block.

It's not something I've used often, but I have used it occasionally.

Andy

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

<86fs3sq05m.fsf@linuxsc.com>

  copy mid

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

  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: Tue, 05 Sep 2023 05:23:17 -0700
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <86fs3sq05m.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> <86sf7xspk3.fsf@linuxsc.com> <JCqIM.79177$m8Ke.22576@fx08.iad> <86zg23r6fi.fsf@linuxsc.com> <0g2JM.580001$U3w1.358152@fx09.iad> <86a5u3qdwt.fsf@linuxsc.com> <w37JM.963104$TPw2.634145@fx17.iad> <86sf7uq01g.fsf@linuxsc.com> <RKlJM.780912$mPI2.44757@fx15.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="6793c8bc2747e0ba6d3890411794594c";
logging-data="2084334"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5efvof0YzfamZhbiS2LgrqVs5g0ykKro="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:aGscR8XnfORX+XZ+3/z3qshMLXc=
sha1:kbQpmk18iwM0xdTKYsXHajk6maY=
 by: Tim Rentsch - Tue, 5 Sep 2023 12:23 UTC

scott@slp53.sl.home (Scott Lurndal) writes:

[ to realloc or malloc/copy/free ? ]

> Most of the code I've worked on has been bare metal (operating
> systems, hypervisors, run-time firmware) where dynamic allocation
> is either discouraged or managed with fixed size pool allocators
> or slab allocators, et cetera. I suppose that's influenced my
> thinking about the desirability of realloc() and run-time heap
> management.
>
> Clearly others have found it useful.

Now that I understand your perspective I think we are on the
same page (no pun intended). Stand-alone environments do
indeed promote a different mindset with respect to malloc()
and to memory allocation generally.

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor