Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You will be married within a year, and divorced within two.


comp / comp.lang.c / Re: realloc() - frequency, conditions, or experiences about relocation?

SubjectAuthor
* realloc() - frequency, conditions, or experiences about relocation?Janis Papanagnou
+* Re: realloc() - frequency, conditions, or experiences about relocation?Bonita Montero
|`* Re: realloc() - frequency, conditions, or experiences about relocation?Vir Campestris
| `* Re: realloc() - frequency, conditions, or experiences about relocation?Bonita Montero
|  `* Re: realloc() - frequency, conditions, or experiences about relocation?Lawrence D'Oliveiro
|   +* Re: realloc() - frequency, conditions, or experiences about relocation?Keith Thompson
|   |+* Re: realloc() - frequency, conditions, or experiences about relocation?David Brown
|   ||+* Re: realloc() - frequency, conditions, or experiences about relocation?Malcolm McLean
|   |||+* Re: realloc() - frequency, conditions, or experiences about relocation?Scott Lurndal
|   ||||`* Re: realloc() - frequency, conditions, or experiences about relocation?Keith Thompson
|   |||| +- Re: realloc() - frequency, conditions, or experiences about relocation?Malcolm McLean
|   |||| `- Re: realloc() - frequency, conditions, or experiences about relocation?Chris M. Thomasson
|   |||`* Re: realloc() - frequency, conditions, or experiences about relocation?Lawrence D'Oliveiro
|   ||| `* Re: realloc() - frequency, conditions, or experiences about relocation?Bonita Montero
|   |||  `- Re: realloc() - frequency, conditions, or experiences about relocation?Lawrence D'Oliveiro
|   ||+* Re: realloc() - frequency, conditions, or experiences about relocation?Chris M. Thomasson
|   |||`- Re: realloc() - frequency, conditions, or experiences about relocation?Bonita Montero
|   ||`- Re: realloc() - frequency, conditions, or experiences about relocation?Lawrence D'Oliveiro
|   |+- Re: realloc() - frequency, conditions, or experiences about relocation?Bonita Montero
|   |`* Re: realloc() - frequency, conditions, or experiences about relocation?Lawrence D'Oliveiro
|   | +* Re: realloc() - frequency, conditions, or experiences about relocation?Keith Thompson
|   | |+- Re: realloc() - frequency, conditions, or experiences about relocation?Richard Damon
|   | |+* Re: realloc() - frequency, conditions, or experiences about relocation?Phil Carmody
|   | ||`- Re: realloc() - frequency, conditions, or experiences about relocation?Keith Thompson
|   | |`* Re: realloc() - frequency, conditions, or experiences about relocation?James Kuyper
|   | | `- Re: realloc() - frequency, conditions, or experiences about relocation?Keith Thompson
|   | `- Re: realloc() - frequency, conditions, or experiences about relocation?James Kuyper
|   `* Re: realloc() - frequency, conditions, or experiences about relocation?Bonita Montero
|    `* Down the hall, past the water cooler, third door on the left... (Was: realloc() Kenny McCormack
|     `- Re: Down the hall, past the water cooler, third door on the left...Bonita Montero
+* Re: realloc() - frequency, conditions, or experiences about relocation?Ben Bacarisse
|`* Re: realloc() - frequency, conditions, or experiences about relocation?Malcolm McLean
| +* Re: realloc() - frequency, conditions, or experiences about relocation?Ben Bacarisse
| |`* Re: realloc() - frequency, conditions, or experiences about relocation?Malcolm McLean
| | +* Re: realloc() - frequency, conditions, or experiences about relocation?Ben Bacarisse
| | |+* Re: realloc() - frequency, conditions, or experiences about relocation?Anton Shepelev
| | ||`* Re: realloc() - frequency, conditions, or experiences about relocation?Tim Rentsch
| | || +* Indefinite pronouns [was:Re: realloc() - frequency, conditions, or experiences aAnton Shepelev
| | || |+* Re: Indefinite pronounsvallor
| | || ||`* Re: Indefinite pronounsDavid Brown
| | || || `- Re: Indefinite pronounsKeith Thompson
| | || |+- Re: Indefinite pronouns [was:Re: realloc() - frequency, conditions, or experiencTim Rentsch
| | || |+- Re: Indefinite pronouns [was:Re: realloc() - frequency, conditions, or experiencCri-Cri
| | || |`* Re: Indefinite pronouns [was:Re: realloc() - frequency, conditions, or experiencKenny McCormack
| | || | `- Re: Indefinite pronouns [was: Re: <something technical>]Janis Papanagnou
| | || `* Re: realloc() - frequency, conditions, or experiences about relocation?Malcolm McLean
| | ||  +* Re: realloc() - frequency, conditions, or experiences about relocation?Malcolm McLean
| | ||  |`* Re: realloc() - frequency, conditions, or experiences about relocation?Lawrence D'Oliveiro
| | ||  | `* Re: realloc() - frequency, conditions, or experiences about relocation?Malcolm McLean
| | ||  |  +- Re: realloc() - frequency, conditions, or experiences about relocation?Ben Bacarisse
| | ||  |  `- Re: realloc() - frequency, conditions, or experiences about relocation?Lawrence D'Oliveiro
| | ||  `* Re: realloc() - frequency, conditions, or experiences about relocation?Tim Rentsch
| | ||   `- Re: realloc() - frequency, conditions, or experiences about relocation?David Brown
| | |+* Re: realloc() - frequency, conditions, or experiences about relocation?Richard Harnden
| | ||`- Re: realloc() - frequency, conditions, or experiences about relocation?Chris M. Thomasson
| | |`- Re: realloc() - frequency, conditions, or experiences about relocation?Malcolm McLean
| | +* Re: realloc() - frequency, conditions, or experiences about relocation?Anton Shepelev
| | |+* Re: realloc() - frequency, conditions, or experiences about relocation?David Duffy
| | ||+* Re: realloc() - frequency, conditions, or experiences about relocation?Malcolm McLean
| | |||+* Re: realloc() - frequency, conditions, or experiences about relocation?Ben Bacarisse
| | ||||`* Re: realloc() - frequency, conditions, or experiences about relocation?David Brown
| | |||| `* Re: realloc() - frequency, conditions, or experiences about relocation?Ben Bacarisse
| | ||||  `- Re: realloc() - frequency, conditions, or experiences about relocation?David Brown
| | |||`* Re: realloc() - frequency, conditions, or experiences about relocation?Anton Shepelev
| | ||| `- Re: realloc() - frequency, conditions, or experiences about relocation?Anton Shepelev
| | ||`- Re: realloc() - frequency, conditions, or experiences about relocation?Anton Shepelev
| | |+- Re: realloc() - frequency, conditions, or experiences about relocation?David Jones
| | |`* Re: realloc() - frequency, conditions, or experiences about relocation?Rich Ulrich
| | | +* Re: realloc() - frequency, conditions, or experiences about relocation?Keith Thompson
| | | |`* Re: realloc() - frequency, conditions, or experiences about relocation?Rich Ulrich
| | | | `* Re: realloc() - frequency, conditions, or experiences about relocation?Anton Shepelev
| | | |  `* Re: realloc() - frequency, conditions, or experiences about relocation?Rich Ulrich
| | | |   `- Re: realloc() - frequency, conditions, or experiences about relocation?Anton Shepelev
| | | `* Re: realloc() - frequency, conditions, or experiences about relocation?Paul
| | |  `* Re: realloc() - frequency, conditions, or experiences about relocation?Rich Ulrich
| | |   `* Re: realloc() - frequency, conditions, or experiences about relocation?Rich Ulrich
| | |    `* Re: realloc() - frequency, conditions, or experiences about relocation?Paul
| | |     +- Re: realloc() - frequency, conditions, or experiences about relocation?James Kuyper
| | |     `- Re: realloc() - frequency, conditions, or experiences about relocation?James Kuyper
| | +* Re: realloc() - frequency, conditions, or experiences about relocation?Keith Thompson
| | |+- Re: realloc() - frequency, conditions, or experiences about relocation?Bonita Montero
| | |`- Re: realloc() - frequency, conditions, or experiences about relocation?Malcolm McLean
| | `* Re: realloc() - frequency, conditions, or experiences about relocation?Scott Lurndal
| |  `- Re: realloc() - frequency, conditions, or experiences about relocation?Chris M. Thomasson
| `- Re: realloc() - frequency, conditions, or experiences about relocation?David Brown
+- Re: realloc() - frequency, conditions, or experiences about relocation?Rosario19
+* Re: realloc() - frequency, conditions, or experiences about relocation?Scott Lurndal
|`* Re: realloc() - frequency, conditions, or experiences about relocation?Michael S
| `- Re: realloc() - frequency, conditions, or experiences about relocation?Scott Lurndal
+- Re: realloc() - frequency, conditions, or experiences about relocation?Janis Papanagnou
+* Re: realloc() - frequency, conditions, or experiences about relocation?David Brown
|`- Re: realloc() - frequency, conditions, or experiences about relocation?Bonita Montero
+- Re: realloc() - frequency, conditions, or experiences about relocation?Chris M. Thomasson
`* Re: realloc() - frequency, conditions, or experiences about relocation?Bonita Montero
 +* Re: realloc() - frequency, conditions, or experiences about relocation?Vir Campestris
 |`* Re: realloc() - frequency, conditions, or experiences about relocation?Bonita Montero
 | `* Re: realloc() - frequency, conditions, or experiences about relocation?Vir Campestris
 |  `- Re: realloc() - frequency, conditions, or experiences about relocation?Bonita Montero
 `* Re: realloc() - frequency, conditions, or experiences about relocation?DFS
  `- Re: realloc() - frequency, conditions, or experiences about relocation?Bonita Montero

Pages:1234
Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: David Brown
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 11:40 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Mon, 24 Jun 2024 13:40:08 +0200
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <v5bluo$thpd$1@dont-email.me>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jun 2024 13:40:09 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="995058d498c537c0d70be20402ad0eb4";
logging-data="968493"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vTdYnJ4a/UTgiDHwegd1+OB9Q1HxpoEs="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:d+uPCGrsgBgoLO0rWd0mEcnpMzM=
In-Reply-To: <875xtyu0kk.fsf@nosuchdomain.example.com>
Content-Language: en-GB
View all headers

On 24/06/2024 11:55, Keith Thompson wrote:

> Something else that occurs to me: If a shrinking realloc() never fails
> in practice, then any code you write to handle a failure won't be
> tested.
>

That is always a problem with allocation functions. Have you ever known
a non-pathological malloc() to fail?

I think, in fact, there's a good argument for ignoring the possibility
of malloc (and calloc and realloc) failures for most PC code. There is
virtually no chance of failure in reality, and if you get one, there is
almost never a sensible way to deal with it - you just kick the can down
the road by having functions return NULL until something gives up and
stops the program with an error message. You might as well just let the
OS kill the program when you try to access memory at address 0.

I've seen more than enough error handling code that has never been
tested in practice - including error handling code with bugs that lead
to far worse problems than just killing the program.

Of course such treatment is not appropriate for all allocations (or
other functions that could fail). But often I think it is better to
write clearer and fully testable (and tested!) code which ignores
hypothetical errors, rather than some of the untestable and untested
jumbles that are sometimes seen in an attempt to "handle" allocation
failures.

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Bonita Montero
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 14:16 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Mon, 24 Jun 2024 16:16:07 +0200
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <v5bv37$vejk$1@raubtier-asyl.eternal-september.org>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jun 2024 16:16:07 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="25e5eda89458a83976f4ab5b7ad682c9";
logging-data="1030772"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19F6+Pp4/qLdNBTYD6cT4nU1oZfo7oGVkM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:PHfZoQZ7MtSXM8DpMEiqWMfdaf8=
Content-Language: de-DE
In-Reply-To: <v5bbd3$rhao$2@dont-email.me>
View all headers

Am 24.06.2024 um 10:40 schrieb Lawrence D'Oliveiro:

> On Fri, 21 Jun 2024 21:12:12 +0200, Bonita Montero wrote:

>> Usually you don't resize the block with a few bytes ...

> The usual way I use realloc is to maintain separate counts of the number
> of array elements I have allocated, and the number I am actually using. A
> realloc call is only needed when the latter hits the former. Every time I
> call realloc, I will extend by some minimum number of array elements (e.g.
> 128), roughly comparable to the sort of array size I typically end up
> with.
> And then when the structure is complete, I do a final realloc call to
> shrink it down so the size is actually that used. Is it safe to assume
> such a call will never fail? Hmm ...

In C++ you dont't have to think about that. Do an emplace_back and the
capacity() doubles with libstdc++ and libc++ if the vevtor becomes full.

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Bonita Montero
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 14:19 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Mon, 24 Jun 2024 16:19:22 +0200
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <v5bv99$vejk$2@raubtier-asyl.eternal-september.org>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jun 2024 16:19:21 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="25e5eda89458a83976f4ab5b7ad682c9";
logging-data="1030772"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gD9gxR94oXCGW953VxdIbwHzN3ws2qHk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:C6XiqpudUSLWcBIFSCK6jB+mzz8=
Content-Language: de-DE
In-Reply-To: <875xtyu0kk.fsf@nosuchdomain.example.com>
View all headers

Am 24.06.2024 um 11:55 schrieb Keith Thompson:
> It's not safe to assume that a shrinking realloc call will never fail.
> It's possible that it will never fail in any existing implementation,
> but the standard makes no such guarantee.

With modern memory allocators a shrink can easily fail if the shrunken
block falls into a different size class and there's no memory for a
block in this class.
mimalloc, jemalloc and TCMalloc round up the size to the next power of
two up to 8kB. If yoz have a 8kB-class block and it shrinks below 4kB
and there's no page (6kB for all mentioned allocators) for this class
and no additional pool can be allocated the shrink fails.

Subject: Down the hall, past the water cooler, third door on the left... (Was: realloc() - frequency, conditions, or experiences about) relocation?
From: Kenny McCormack
Newsgroups: comp.lang.c
Organization: The official candy of the new Millennium
Date: Mon, 24 Jun 2024 15:44 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Down the hall, past the water cooler, third door on the left... (Was: realloc() - frequency, conditions, or experiences about)
relocation?
Date: Mon, 24 Jun 2024 15:44:56 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <v5c49o$2ko7p$2@news.xmission.com>
References: <v4ojs8$gvji$1@dont-email.me> <v54jac$3a4p2$1@raubtier-asyl.eternal-september.org> <v5bbd3$rhao$2@dont-email.me> <v5bv37$vejk$1@raubtier-asyl.eternal-september.org>
Injection-Date: Mon, 24 Jun 2024 15:44:56 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="2777337"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
View all headers

In article <v5bv37$vejk$1@raubtier-asyl.eternal-september.org>,
....
>In C++ you dont't have to think about that.

You don't have to worry about it in Fortran, either.

--
"He is exactly as they taught in KGB school: an egoist, a liar, but talented - he
knows the mind of the wrestling-loving, under-educated, authoritarian-admiring
white male populous."
- Malcolm Nance, p59. -

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Tim Rentsch
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 16:32 UTC
References: 1 2 3 4 5 6 7 8 9
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17687@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
Date: Mon, 24 Jun 2024 09:32:40 -0700
Organization: A noiseless patient Spider
Lines: 94
Message-ID: <86wmmee1xz.fsf@linuxsc.com>
References: <v4ojs8$gvji$1@dont-email.me> <875xu8vsen.fsf@bsb.me.uk> <v4ovqf$j5hq$1@dont-email.me> <87zfrjvqp6.fsf@bsb.me.uk> <v4pb4v$lhgk$1@dont-email.me> <87tthrvdtg.fsf@bsb.me.uk> <20240617181034.74fb4cca1f4a9a3ea032825e@g{oogle}mail.com> <86r0cuk9qz.fsf@linuxsc.com> <v4rmv0$19t6u$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Mon, 24 Jun 2024 18:32:42 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b3b1304951eae8dc1e53ef86c96f1e35";
logging-data="1084362"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18lZ2RrPexl6QEYWz6eTRBGjgc9GWLV0Mo="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:79pi2rvS59cLtIh8LbjYD/+WOhc=
sha1:qApZITr8cFbwTjHQVmkKEG1GqbA=
View all headers

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

> On 18/06/2024 08:09, Tim Rentsch wrote:
>
>> Anton Shepelev <anton.txt@g{oogle}mail.com> writes:
>>
>>> Ben Bacarisse to Malcolm McLean:
>>>
>>>> [next is a comment from Malcolm]
>>>>
>>>>> Your strategy for avoiding these extremes is exponential
>>>>> growth.
>>>>
>>>> It's odd to call it mine. It's very widely know and used.
>>>> "The one I mentioned" might be less confusing description.
>>>
>>> I think it is a modern English idiom, which I dislike as
>>> well. StackOverflow is full of questions starting like:
>>> "How do you do this?" and "How do I do that?" They are
>>> informal ways of the more literary "How does one do this?"
>>> or "What is the way to do that?"
>>
>> I have a different take here. First the "your" of "your
>> strategy" reads as a definite pronoun, meaning it refers
>> specifically to Ben and not to some unknown other party.
>> (And incidentally is subtly insulting because of that,
>> whether it was meant that way or not.)
>>
>> Second the use of "you" to mean an unspecified other person
>> is not idiom but standard usage. The word "you" is both a
>> definite pronoun and an indefinite pronoun, depending on
>> context. The word "they" also has this property. Consider
>> these two examples:
>>
>> The bank downtown was robbed. They haven't been caught
>> yet.
>>
>> They say the sheriff isn't going to run for re-election.
>>
>> In the first example "they" is a definite pronoun, referring
>> to the people who robbed the bank. In the second example,
>> "they" is an indefinite pronoun, referring to unspecified
>> people in general (perhaps but not necessarily everyone).
>> The word "you" is similar: it can mean specifically the
>> listener, or it can mean generically anyone in a broader
>> audience, even those who never hear or read the statement
>> with "you" in it.
>>
>> The word "one" used as a pronoun is more formal, and to me
>> at least often sounds stilted. In US English "one" is most
>> often an indefinite pronoun, either second person or third
>> person. But "one" can also be used as a first person
>> definite pronoun (referring to the speaker), which an online
>> reference tells me is chiefly British English. (I would
>> guess that this usage predominates in "the Queen's English"
>> dialect of English, but I have very little experience in
>> such things.)
>>
>> Finally I would normally read "I" as a first person definite
>> pronoun, and not an indefinite pronoun. So I don't have any
>> problem with someone saying "how should I ..." when asking
>> for advice. They aren't asking how someone else should ...
>> but how they should ..., and what advice I might give could
>> very well depend on who is doing the asking.
>
> Ben said
>
>> Restore snipped Ben upthread
>
> "In practice, the cost is usually moderate and can be very
> effectively managed by using an exponential allocation scheme: at
> every reallocation multiply the storage space by some factor greater
> than 1 (I often use 3/2, but doubling is often used as well)."
>
> So it's open and shut, and no two ways about it. Ben's strategy is
> exponential growth. And to be fair I use that strategy myself in
> functions like fslutp(). It's only not Ben's strategy if we mean to
> imply that Ben was the first person to use expoential growth, or the
> first to understand the mathematical implications, and of course
> that's not the case. It was all worked out by Euler long before any
> of us were born. [...]

You have an annoying habit. Your writing often comes across as
authoritarian and somewhat condescending. Furthermore you tend not
to listen very well. Your response above is a case in point. You
ignore what I'm talking about (which is not whether Ben uses an
exponential growth strategy, or whether such a strategy is "Ben's"
or not), and instead talk about something that is irrelevant to what
I was saying. You have completely missed the point. Your comments
do nothing to extend the conversation. From where I sit all they do
is cause irritation and illustrate how muddled your thinking is.
I'm sure this isn't the first time you've heard comments along these
lines. It would be nice if you would make an effort to improve
your behavior in light of these repeated comments.

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: David Brown
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 17:19 UTC
References: 1 2 3 4 5 6 7 8 9 10
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Mon, 24 Jun 2024 19:19:38 +0200
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <v5c9rb$1159j$2@dont-email.me>
References: <v4ojs8$gvji$1@dont-email.me> <875xu8vsen.fsf@bsb.me.uk>
<v4ovqf$j5hq$1@dont-email.me> <87zfrjvqp6.fsf@bsb.me.uk>
<v4pb4v$lhgk$1@dont-email.me> <87tthrvdtg.fsf@bsb.me.uk>
<20240617181034.74fb4cca1f4a9a3ea032825e@g{oogle}mail.com>
<86r0cuk9qz.fsf@linuxsc.com> <v4rmv0$19t6u$1@dont-email.me>
<86wmmee1xz.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jun 2024 19:19:39 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="995058d498c537c0d70be20402ad0eb4";
logging-data="1086771"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Df/3eZ/GZXr12Ha3FlMY2mY9DaKHxel8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:nUW35C0RrDSxYy66Z9E5TpURqh0=
In-Reply-To: <86wmmee1xz.fsf@linuxsc.com>
Content-Language: en-GB
View all headers

On 24/06/2024 18:32, Tim Rentsch wrote:
>
> You have an annoying habit. Your writing often comes across as
> authoritarian and somewhat condescending. Furthermore you tend not
> to listen very well.

The irony of that post is /astounding/.

I have met few people with a greater knowledge and insight in the C
language than you. And I have met few with less self-insight.

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Malcolm McLean
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 17:50 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm.arthur.mclean@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Mon, 24 Jun 2024 18:50:15 +0100
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <v5cbkn$11tla$1@dont-email.me>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com>
<v5bluo$thpd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 24 Jun 2024 19:50:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="67c61ba4668adca48db563acd23b2103";
logging-data="1111722"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+09IPjt+VHZtekyZZ1Fus71A9Ix6ZNnIw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:VAjh861MBRUzowLqYMroFSRZ+Kg=
Content-Language: en-GB
In-Reply-To: <v5bluo$thpd$1@dont-email.me>
View all headers

On 24/06/2024 12:40, David Brown wrote:
> On 24/06/2024 11:55, Keith Thompson wrote:
>
>> Something else that occurs to me: If a shrinking realloc() never fails
>> in practice, then any code you write to handle a failure won't be
>> tested.
>>
>
> That is always a problem with allocation functions.  Have you ever known
> a non-pathological malloc() to fail?
>
> I think, in fact, there's a good argument for ignoring the possibility
> of malloc (and calloc and realloc) failures for most PC code.  There is
> virtually no chance of failure in reality, and if you get one, there is
> almost never a sensible way to deal with it - you just kick the can down
> the road by having functions return NULL until something gives up and
> stops the program with an error message.  You might as well just let the
> OS kill the program when you try to access memory at address 0.
>
> I've seen more than enough error handling code that has never been
> tested in practice - including error handling code with bugs that lead
> to far worse problems than just killing the program.
>
> Of course such treatment is not appropriate for all allocations (or
> other functions that could fail).  But often I think it is better to
> write clearer and fully testable (and tested!) code which ignores
> hypothetical errors, rather than some of the untestable and untested
> jumbles that are sometimes seen in an attempt to "handle" allocation
> failures.
>
>
Baby X has bbx_malloc() which is guaranteed never to return NULL, and
never to return a pointer to an allocation which cannot be indexed by an
int.

I use a "goto out_of_memory" in regular code, however.

--
Check out my hobby project.
http://malcolmmclean.github.io/babyxrc

Subject: Re: Down the hall, past the water cooler, third door on the left... (Was: realloc() - frequency, conditions, or experiences about) relocation?
From: Bonita Montero
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 18:16 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Down the hall, past the water cooler, third door on the left...
(Was: realloc() - frequency, conditions, or experiences about) relocation?
Date: Mon, 24 Jun 2024 20:16:45 +0200
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <v5cd6b$127vp$1@raubtier-asyl.eternal-september.org>
References: <v4ojs8$gvji$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me>
<v5bv37$vejk$1@raubtier-asyl.eternal-september.org>
<v5c49o$2ko7p$2@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 24 Jun 2024 20:16:44 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="25e5eda89458a83976f4ab5b7ad682c9";
logging-data="1122297"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19q7E05Viw9CbOkxlgTBZFvNYOMI/Ru+nE="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:n/hqp5btk9X5aCnbtaqbiWQ2GrM=
In-Reply-To: <v5c49o$2ko7p$2@news.xmission.com>
Content-Language: de-DE
View all headers

Am 24.06.2024 um 17:44 schrieb Kenny McCormack:
> In article <v5bv37$vejk$1@raubtier-asyl.eternal-september.org>,
> ...
>> In C++ you dont't have to think about that.
>
> You don't have to worry about it in Fortran, either.

But Fortran is for sure not that flexible that you could build your
own containers basing on the same logic, partitially with lowlevel
facilities which are derived from C. I implemnented a parallel hash
map with some reader writer's locks which feel rather like a native
component of the language; try this with Fortran.

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Scott Lurndal
Newsgroups: comp.lang.c
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 24 Jun 2024 18:20 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!tncsrv06.tnetconsulting.net!newsfeed.endofthelinebbs.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx11.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: scott@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
Newsgroups: comp.lang.c
References: <v4ojs8$gvji$1@dont-email.me> <v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org> <v52270$2nli8$1@dont-email.me> <v54jac$3a4p2$1@raubtier-asyl.eternal-september.org> <v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com> <v5bluo$thpd$1@dont-email.me> <v5cbkn$11tla$1@dont-email.me>
Lines: 20
Message-ID: <QNieO.108090$ED9b.88071@fx11.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 24 Jun 2024 18:20:32 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 24 Jun 2024 18:20:32 GMT
X-Received-Bytes: 1712
View all headers

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>On 24/06/2024 12:40, David Brown wrote:

>> Of course such treatment is not appropriate for all allocations (or
>> other functions that could fail).  But often I think it is better to
>> write clearer and fully testable (and tested!) code which ignores
>> hypothetical errors, rather than some of the untestable and untested
>> jumbles that are sometimes seen in an attempt to "handle" allocation
>> failures.
>>
>>
>Baby X has bbx_malloc() which is guaranteed never to return NULL, and
>never to return a pointer to an allocation which cannot be indexed by an
>int.

What do you mean by 'indexed by an int'? So, what happens if I index
your allocation with -109235?

Or did you mean to say unsigned (or positive) int less than the
size of the allocation?

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Chris M. Thomasson
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 19:33 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Mon, 24 Jun 2024 12:33:04 -0700
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <v5chlg$12vsd$1@dont-email.me>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com>
<v5bluo$thpd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 24 Jun 2024 21:33:05 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="07ac9ec5e7d723e4c5066c38c1039c91";
logging-data="1146765"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18RYIImGyv2x12v2IYylz7NL8HJ0Y5EcWM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:qejaI908dipFR6OQrZdZ6CntHvI=
In-Reply-To: <v5bluo$thpd$1@dont-email.me>
Content-Language: en-US
View all headers

On 6/24/2024 4:40 AM, David Brown wrote:
> On 24/06/2024 11:55, Keith Thompson wrote:
>
>> Something else that occurs to me: If a shrinking realloc() never fails
>> in practice, then any code you write to handle a failure won't be
>> tested.
>>
>
> That is always a problem with allocation functions.  Have you ever known
> a non-pathological malloc() to fail?
>
> I think, in fact, there's a good argument for ignoring the possibility
> of malloc (and calloc and realloc) failures for most PC code.  There is
> virtually no chance of failure in reality, and if you get one, there is
> almost never a sensible way to deal with it -
[...]

I have had to deal and roll with malloc failures. It put the server in
panic mode and it started killing connections that were already timed
out, dumping some caches (freelists of regions, ect), ect... There is a
way to recover.

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Bonita Montero
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 19:48 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Mon, 24 Jun 2024 21:48:16 +0200
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <v5cihu$13b6q$1@raubtier-asyl.eternal-september.org>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com>
<v5bluo$thpd$1@dont-email.me> <v5chlg$12vsd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 24 Jun 2024 21:48:15 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="25e5eda89458a83976f4ab5b7ad682c9";
logging-data="1158362"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+DmJkWnmexYXgv31RSYUDywL50FSGUjFk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:xlr31NPo/ac1sOuCqu6YDh4+mM0=
In-Reply-To: <v5chlg$12vsd$1@dont-email.me>
Content-Language: de-DE
View all headers

Am 24.06.2024 um 21:33 schrieb Chris M. Thomasson:
> On 6/24/2024 4:40 AM, David Brown wrote:
>> On 24/06/2024 11:55, Keith Thompson wrote:
>>
>>> Something else that occurs to me: If a shrinking realloc() never fails
>>> in practice, then any code you write to handle a failure won't be
>>> tested.
>>>
>>
>> That is always a problem with allocation functions.  Have you ever
>> known a non-pathological malloc() to fail?
>>
>> I think, in fact, there's a good argument for ignoring the possibility
>> of malloc (and calloc and realloc) failures for most PC code.  There
>> is virtually no chance of failure in reality, and if you get one,
>> there is almost never a sensible way to deal with it -
> [...]
>
> I have had to deal and roll with malloc failures. It put the server in
> panic mode and it started killing connections that were already timed
> out, dumping some caches (freelists of regions, ect), ect... There is a
> way to recover.
>

There are applications where you can ignore malloc()-failures /
bad_alloc since they only allocate a small amount of memory or
a lot of small allocations which sum up to a small amount of
memory.

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Keith Thompson
Newsgroups: comp.lang.c
Organization: None to speak of
Date: Mon, 24 Jun 2024 21:28 UTC
References: 1 2 3 4 5 6 7 8 9
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
Date: Mon, 24 Jun 2024 14:28:47 -0700
Organization: None to speak of
Lines: 19
Message-ID: <87r0cmrpww.fsf@nosuchdomain.example.com>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me>
<875xtyu0kk.fsf@nosuchdomain.example.com>
<v5bluo$thpd$1@dont-email.me> <v5cbkn$11tla$1@dont-email.me>
<QNieO.108090$ED9b.88071@fx11.iad>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Mon, 24 Jun 2024 23:28:47 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0a690d6294358a2c4bce5879f14e083a";
logging-data="1184163"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18606JlZ2wAbQoz7zSiNEbE"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:5VQ7XQhbQl6LvbICQF67DdVxkBE=
sha1:CP2U/x0xJxNqWySVP6gIMJA5uh4=
View all headers

scott@slp53.sl.home (Scott Lurndal) writes:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
[...]
>>Baby X has bbx_malloc() which is guaranteed never to return NULL, and
>>never to return a pointer to an allocation which cannot be indexed by an
>>int.
>
> What do you mean by 'indexed by an int'? So, what happens if I index
> your allocation with -109235?
>
> Or did you mean to say unsigned (or positive) int less than the
> size of the allocation?

If I recall correctly, Malcolm hates size_t. I presume that
bbx_malloc() will never allocate more than INT_MAX bytes.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Lawrence D'Oliv
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 22:59 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Mon, 24 Jun 2024 22:59:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <v5ctoa$15hrn$1@dont-email.me>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com>
<v5bluo$thpd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Jun 2024 00:59:23 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="250b38e1e4730787d8a829a06e323428";
logging-data="1230711"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ctdutSdIGpKorjNkWhWrk"
User-Agent: Pan/0.158 (Avdiivka; )
Cancel-Lock: sha1:sZAxEOO4OhEi8OowHCStK1RJMBA=
View all headers

On Mon, 24 Jun 2024 13:40:08 +0200, David Brown wrote:

> Have you ever known a non-pathological malloc() to fail?

I was once commissioned, many decades ago, to write a multispectral image
viewer to run on old MacOS. I followed my usual memory-allocation
discipline. The client reported how he tried to open too many images at
once, and ran out of memory; my program reported one out-of-memory error,
gave up trying to open the rest of the files, and gracefully recovered
without crashing.

The program that had been supplied to him for Microsoft Windows, however,
gave an error for *each* file it failed to open.

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Malcolm McLean
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Mon, 24 Jun 2024 23:22 UTC
References: 1 2 3 4 5 6 7 8 9 10
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm.arthur.mclean@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Tue, 25 Jun 2024 00:22:04 +0100
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <v5cv2s$15rhq$1@dont-email.me>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com>
<v5bluo$thpd$1@dont-email.me> <v5cbkn$11tla$1@dont-email.me>
<QNieO.108090$ED9b.88071@fx11.iad> <87r0cmrpww.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 25 Jun 2024 01:22:05 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1e626826c1de0f9e3b27ede86e212f68";
logging-data="1240634"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18d0zpjScYmJaR252axSbIrKEPxw2xs8PY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:PosIeh9v3KrHwfWFJMO9kgA/uSc=
Content-Language: en-GB
In-Reply-To: <87r0cmrpww.fsf@nosuchdomain.example.com>
View all headers

On 24/06/2024 22:28, Keith Thompson wrote:
> scott@slp53.sl.home (Scott Lurndal) writes:
>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
> [...]
>>> Baby X has bbx_malloc() which is guaranteed never to return NULL, and
>>> never to return a pointer to an allocation which cannot be indexed by an
>>> int.
>>
>> What do you mean by 'indexed by an int'? So, what happens if I index
>> your allocation with -109235?
>>
>> Or did you mean to say unsigned (or positive) int less than the
>> size of the allocation?
>
> If I recall correctly, Malcolm hates size_t. I presume that
> bbx_malloc() will never allocate more than INT_MAX bytes.
>
Exactly.
Currently bbx_malloc() does take a size_t, but there version in which it
takes an int. However you get warning sif yiub try something like
bbx_mallcc(10 * sizeof(int)) on the basis that expressin is size_t.

But if you pass either a negative number or more than iNT_MAX, it
assumes the request is invalid and terminates with an error message.

--
Check out my hobby project.
http://malcolmmclean.github.io/babyxrc

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Chris M. Thomasson
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 01:31 UTC
References: 1 2 3 4 5 6 7 8 9 10
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Mon, 24 Jun 2024 18:31:48 -0700
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <v5d6m5$1769p$1@dont-email.me>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com>
<v5bluo$thpd$1@dont-email.me> <v5cbkn$11tla$1@dont-email.me>
<QNieO.108090$ED9b.88071@fx11.iad> <87r0cmrpww.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 25 Jun 2024 03:31:49 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="a0475ea1831d78ec58c17d06517ed380";
logging-data="1284409"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18CZ4XvHy799ZxGTFP8K4r7l6q2HdnLGPk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:bDVihlfwqa151mtvzA+7WvkErx8=
In-Reply-To: <87r0cmrpww.fsf@nosuchdomain.example.com>
Content-Language: en-US
View all headers

On 6/24/2024 2:28 PM, Keith Thompson wrote:
> scott@slp53.sl.home (Scott Lurndal) writes:
>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
> [...]
>>> Baby X has bbx_malloc() which is guaranteed never to return NULL, and
>>> never to return a pointer to an allocation which cannot be indexed by an
>>> int.
>>
>> What do you mean by 'indexed by an int'? So, what happens if I index
>> your allocation with -109235?
>>
>> Or did you mean to say unsigned (or positive) int less than the
>> size of the allocation?
>
> If I recall correctly, Malcolm hates size_t. I presume that
> bbx_malloc() will never allocate more than INT_MAX bytes.
>

He still has to deal with bbx_malloc failing. Don't like automatically
aborting...

bbx_malloc(INT_MAX);
bbx_malloc(INT_MAX);
bbx_malloc(INT_MAX);
....

;^)

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Lawrence D'Oliv
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 07:02 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Tue, 25 Jun 2024 07:02:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <v5dq2e$1eh23$11@dont-email.me>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Jun 2024 09:02:39 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="250b38e1e4730787d8a829a06e323428";
logging-data="1524803"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+SGjpL9StpPMC2kahBnJRU"
User-Agent: Pan/0.158 (Avdiivka; )
Cancel-Lock: sha1:HwjaYzZ7Kvw+8pyEo3UIcnw3XRY=
View all headers

On Mon, 24 Jun 2024 02:55:39 -0700, Keith Thompson wrote:

> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>
>> The usual way I use realloc is to maintain separate counts of the
>> number of array elements I have allocated, and the number I am actually
>> using. A realloc call is only needed when the latter hits the former.
>> Every time I call realloc, I will extend by some minimum number of
>> array elements (e.g. 128), roughly comparable to the sort of array size
>> I typically end up with.
>>
>> And then when the structure is complete, I do a final realloc call to
>> shrink it down so the size is actually that used. Is it safe to assume
>> such a call will never fail? Hmm ...
>
> It's not safe to assume that a shrinking realloc call will never fail.
> It's possible that it will never fail in any existing implementation,
> but the standard makes no such guarantee.
>
> ...
>
> Having said all that, if realloc fails (indicated by returning a null
> pointer), you still have the original pointer to the object.

In other words, it’s safe to ignore any error from that last shrinking
realloc? That’s good enough for me. ;)

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Lawrence D'Oliv
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 07:06 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Tue, 25 Jun 2024 07:06:41 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <v5dqa0$1eh23$12@dont-email.me>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com>
<v5bluo$thpd$1@dont-email.me> <v5cbkn$11tla$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Jun 2024 09:06:41 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="250b38e1e4730787d8a829a06e323428";
logging-data="1524803"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BpcorlTT9w2x8WCInWzSM"
User-Agent: Pan/0.158 (Avdiivka; )
Cancel-Lock: sha1:Y2kUbUVXf2vvvqpAaGkuvCuMYyI=
View all headers

On Mon, 24 Jun 2024 18:50:15 +0100, Malcolm McLean wrote:

> Baby X has bbx_malloc() which is guaranteed never to return NULL ...

Does it actually allocate the (physical) memory?

I wrote a memory-hog app for Android once, and found that allocating large
amounts of memory space had very little impact on the system. Then when I
added code to actually write data into those allocated pages, that’s when
it really started to break into a sweat ...

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Bonita Montero
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 08:38 UTC
References: 1 2 3 4 5 6 7 8 9
Path: eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Tue, 25 Jun 2024 10:38:28 +0200
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <v5dvm3$1fo3c$1@raubtier-asyl.eternal-september.org>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com>
<v5bluo$thpd$1@dont-email.me> <v5cbkn$11tla$1@dont-email.me>
<v5dqa0$1eh23$12@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Jun 2024 10:38:27 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="e5f07f45ab734ec04a76043ad492dd64";
logging-data="1564780"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+juDu/seskA6/aX3Y4L+xASgrT4nYKmeU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:R/GFBf8j3h+QCFpGsxmK/iQHs2I=
In-Reply-To: <v5dqa0$1eh23$12@dont-email.me>
Content-Language: de-DE
View all headers

Am 25.06.2024 um 09:06 schrieb Lawrence D'Oliveiro:

> I wrote a memory-hog app for Android once, and found that allocating large
> amounts of memory space had very little impact on the system. Then when I
> added code to actually write data into those allocated pages, that’s when
> it really started to break into a sweat ...

Then android is also doing overcommit.

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Bonita Montero
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 08:48 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Tue, 25 Jun 2024 10:48:33 +0200
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <v5e090$1fr82$1@raubtier-asyl.eternal-september.org>
References: <v4ojs8$gvji$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 25 Jun 2024 10:48:32 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="e5f07f45ab734ec04a76043ad492dd64";
logging-data="1568002"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/oLYhCHdBfGr+eWZYE0oHFbTuk0kAfYoY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:grmAW8l9TFDEFz8fZmL0b9ifup0=
Content-Language: de-DE
In-Reply-To: <v4ojs8$gvji$1@dont-email.me>
View all headers

Test this code with your Linux installation. For my installation
glibc does all realloc()ations in-place. Really surprising for me.

#include <stdio.h>
#include <stdlib.h>

int main()
{ void *p = malloc( 0x100000000 );
printf( "%p\n", p );
p = realloc( p, 1 );
printf( "%p\n", p );
malloc( 0x100000000 - 0x10000 );
p = realloc( p, 0x100000000 );
printf( "%p\n", p );
}

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Keith Thompson
Newsgroups: comp.lang.c
Organization: None to speak of
Date: Tue, 25 Jun 2024 10:05 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
Date: Tue, 25 Jun 2024 03:05:16 -0700
Organization: None to speak of
Lines: 47
Message-ID: <87frt1tk0z.fsf@nosuchdomain.example.com>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me>
<875xtyu0kk.fsf@nosuchdomain.example.com>
<v5dq2e$1eh23$11@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Jun 2024 12:05:17 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e9e079a2606fcbb785c539789babdee9";
logging-data="1590333"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/guWwMHt4SmVzDjLwP94s1"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:z18aROCIPMeUysn79DVQL39q2oM=
sha1:2krSndj9/uKwBsXbT5vkJmOPaSE=
View all headers

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> On Mon, 24 Jun 2024 02:55:39 -0700, Keith Thompson wrote:
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>> The usual way I use realloc is to maintain separate counts of the
>>> number of array elements I have allocated, and the number I am actually
>>> using. A realloc call is only needed when the latter hits the former.
>>> Every time I call realloc, I will extend by some minimum number of
>>> array elements (e.g. 128), roughly comparable to the sort of array size
>>> I typically end up with.
>>>
>>> And then when the structure is complete, I do a final realloc call to
>>> shrink it down so the size is actually that used. Is it safe to assume
>>> such a call will never fail? Hmm ...
>>
>> It's not safe to assume that a shrinking realloc call will never fail.
>> It's possible that it will never fail in any existing implementation,
>> but the standard makes no such guarantee.
>>
>> ...
>>
>> Having said all that, if realloc fails (indicated by returning a null
>> pointer), you still have the original pointer to the object.
>
> In other words, it’s safe to ignore any error from that last shrinking
> realloc? That’s good enough for me. ;)

What? No, that's not what I said at all.

Suppose you do something like:

some_type *p = malloc(BIG_VALUE);
// ...
p = realloc(p, SMALL_VALUE);

If the realloc() succeeds and doesn't relocate and copy the object,
you're fine. If realloc() succeeds and *does* relocate the object, p
still points to memory that has now been deallocated, and you don't have
a pointer to the newly allocated memory. If realloc() fails, it returns
a null pointer, but the original memory is still valid -- but again, the
assignment clobbers your only pointer to it.

I presume you can write code that handles all three possibilities, but
you can't just ignore any errors.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Vir Campestris
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 10:55 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vir.campestris@invalid.invalid (Vir Campestris)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Tue, 25 Jun 2024 11:55:02 +0100
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <v5e7m6$1gt2p$3@dont-email.me>
References: <v4ojs8$gvji$1@dont-email.me>
<v5e090$1fr82$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Jun 2024 12:55:02 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3f6c8e2312376624d05789080f0e48eb";
logging-data="1602649"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NZUvLNEBeE48gvTf1PSNSoOekBJWw1W4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:kUMdcXdPg/+2IqNh1fRKTAhA5hE=
In-Reply-To: <v5e090$1fr82$1@raubtier-asyl.eternal-september.org>
Content-Language: en-GB
View all headers

On 25/06/2024 09:48, Bonita Montero wrote:
> Test this code with your Linux installation. For my installation
> glibc does all realloc()ations in-place. Really surprising for me.
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main()
> {
>     void *p = malloc( 0x100000000 );
>     printf( "%p\n", p );
>     p = realloc( p, 1 );
>     printf( "%p\n", p );
>     malloc( 0x100000000 - 0x10000 );
>     p = realloc( p, 0x100000000 );
>     printf( "%p\n", p );
> }
Try allocating a bunch of little items, and looking at where they are.
They'll likely be contiguous, or evenly spaced, depending on your
implementation and what "little" is.

Then resize them all. Some will move.

Andy.
--
Your C++ comment up-thread BTW is off-topic here. My favourite C++
container is vector, and that has a reserve call so you can keep growing
the container without lots of reallocations.

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Richard Damon
Newsgroups: comp.lang.c
Organization: i2pn2 (i2pn.org)
Date: Tue, 25 Jun 2024 11:21 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!panix!weretis.net!feeder9.news.weretis.net!news.nk.ca!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: richard@damon-family.org (Richard Damon)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Tue, 25 Jun 2024 07:21:42 -0400
Organization: i2pn2 (i2pn.org)
Message-ID: <v5e986$12a19$1@i2pn2.org>
References: <v4ojs8$gvji$1@dont-email.me>
<v4ov8h$j2q2$1@raubtier-asyl.eternal-september.org>
<v52270$2nli8$1@dont-email.me>
<v54jac$3a4p2$1@raubtier-asyl.eternal-september.org>
<v5bbd3$rhao$2@dont-email.me> <875xtyu0kk.fsf@nosuchdomain.example.com>
<v5dq2e$1eh23$11@dont-email.me> <87frt1tk0z.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Jun 2024 11:21:42 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="1124393"; mail-complaints-to="usenet@i2pn2.org";
posting-account="diqKR1lalukngNWEqoq9/uFtbkm5U+w3w6FQ0yesrXg";
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <87frt1tk0z.fsf@nosuchdomain.example.com>
X-Spam-Checker-Version: SpamAssassin 4.0.0
View all headers

On 6/25/24 6:05 AM, Keith Thompson wrote:
> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>> On Mon, 24 Jun 2024 02:55:39 -0700, Keith Thompson wrote:
>>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>>> The usual way I use realloc is to maintain separate counts of the
>>>> number of array elements I have allocated, and the number I am actually
>>>> using. A realloc call is only needed when the latter hits the former.
>>>> Every time I call realloc, I will extend by some minimum number of
>>>> array elements (e.g. 128), roughly comparable to the sort of array size
>>>> I typically end up with.
>>>>
>>>> And then when the structure is complete, I do a final realloc call to
>>>> shrink it down so the size is actually that used. Is it safe to assume
>>>> such a call will never fail? Hmm ...
>>>
>>> It's not safe to assume that a shrinking realloc call will never fail.
>>> It's possible that it will never fail in any existing implementation,
>>> but the standard makes no such guarantee.
>>>
>>> ...
>>>
>>> Having said all that, if realloc fails (indicated by returning a null
>>> pointer), you still have the original pointer to the object.
>>
>> In other words, it’s safe to ignore any error from that last shrinking
>> realloc? That’s good enough for me. ;)
>
> What? No, that's not what I said at all.
>
> Suppose you do something like:
>
> some_type *p = malloc(BIG_VALUE);
> // ...
> p = realloc(p, SMALL_VALUE);
>
> If the realloc() succeeds and doesn't relocate and copy the object,
> you're fine. If realloc() succeeds and *does* relocate the object, p
> still points to memory that has now been deallocated, and you don't have
> a pointer to the newly allocated memory. If realloc() fails, it returns
> a null pointer, but the original memory is still valid -- but again, the
> assignment clobbers your only pointer to it.
>
> I presume you can write code that handles all three possibilities, but
> you can't just ignore any errors.
>

The idiom I always learned for realloc was something like:

some_type *p = malloc(size);
if (!p) {
// allocation failed, do something about it. (might be just abort)
}

....

some_type *np = realloc(p, new_size);
if (np) {
p = np;
} else {
// p still points to old buffer, but you didn't get the new size
// so do what you can to handle the situation.
}

// p here points to the current buffer,
// might be the old size or the new.

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Bonita Montero
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 11:28 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Tue, 25 Jun 2024 13:28:51 +0200
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <v5e9li$1hil5$1@raubtier-asyl.eternal-september.org>
References: <v4ojs8$gvji$1@dont-email.me>
<v5e090$1fr82$1@raubtier-asyl.eternal-september.org>
<v5e7m6$1gt2p$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Jun 2024 13:28:51 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="e5f07f45ab734ec04a76043ad492dd64";
logging-data="1624741"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/+1CMTnrN/1V8Yj30PtuOXtepE+4Q7+1w="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:hU2DdJRNFvLLqImcKc+eOrg2Lzc=
Content-Language: de-DE
In-Reply-To: <v5e7m6$1gt2p$3@dont-email.me>
View all headers

Am 25.06.2024 um 12:55 schrieb Vir Campestris:
> On 25/06/2024 09:48, Bonita Montero wrote:
>> Test this code with your Linux installation. For my installation
>> glibc does all realloc()ations in-place. Really surprising for me.
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> int main()
>> {
>>      void *p = malloc( 0x100000000 );
>>      printf( "%p\n", p );
>>      p = realloc( p, 1 );
>>      printf( "%p\n", p );
>>      malloc( 0x100000000 - 0x10000 );
>>      p = realloc( p, 0x100000000 );
>>      printf( "%p\n", p );
>> }
> Try allocating a bunch of little items, and looking at where they are.
> They'll likely be contiguous, or evenly spaced, depending on your
> implementation and what "little" is.
>
> Then resize them all. Some will move.
>
> Andy.

The interesting part is that after doing the first realloc()
the memory being freee isn't reused for the next malloc().

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: DFS
Newsgroups: comp.lang.c
Date: Tue, 25 Jun 2024 13:56 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-3.nntp.ord.giganews.com!border-4.nntp.ord.giganews.com!nntp.giganews.com!news-out.netnews.com!postmaster.netnews.com!us8.netnews.com!not-for-mail
X-Trace: DXC=m2=nR8GMGd[>gCnG5fMoN\HWonT5<]0T]Q;nb^V>PUfV5[gZBW6J?L\>8J_kK>kdRYI]PP9U=83H\>bl72nREV]YMba][>SC2CWf;]EoU=id5V=R<hY6_C9TX
X-Complaints-To: support@blocknews.net
Date: Tue, 25 Jun 2024 09:56:58 -0400
MIME-Version: 1.0
User-Agent: Betterbird (Windows)
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Newsgroups: comp.lang.c
References: <v4ojs8$gvji$1@dont-email.me>
<v5e090$1fr82$1@raubtier-asyl.eternal-september.org>
Content-Language: en-US
From: nospam@dfs.com (DFS)
In-Reply-To: <v5e090$1fr82$1@raubtier-asyl.eternal-september.org>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 31
Message-ID: <667accaa$0$2873016$882e4bbb@reader.netnews.com>
NNTP-Posting-Host: 127.0.0.1
X-Trace: 1719323818 reader.netnews.com 2873016 127.0.0.1:56557
View all headers

On 6/25/2024 4:48 AM, Bonita Montero wrote:
> Test this code with your Linux installation. For my installation
> glibc does all realloc()ations in-place. Really surprising for me.
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main()
> {
>     void *p = malloc( 0x100000000 );
>     printf( "%p\n", p );
>     p = realloc( p, 1 );
>     printf( "%p\n", p );
>     malloc( 0x100000000 - 0x10000 );
>     p = realloc( p, 0x100000000 );
>     printf( "%p\n", p );
> }

$ gcc -Wall montera_test.c -o mt
montera_test.c: In function ‘main’:
montera_test.c:10:9: warning: ignoring return value of ‘malloc’ declared
with attribute ‘warn_unused_result’ [-Wunused-result]
10 | malloc( 0x100000000 - 0x10000 );
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

$ ./mt
0x7fb976f12010
0x7fb976f12010
0x7fb876f11010

Subject: Re: realloc() - frequency, conditions, or experiences about relocation?
From: Bonita Montero
Newsgroups: comp.lang.c
Organization: A noiseless patient Spider
Date: Tue, 25 Jun 2024 14:16 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: realloc() - frequency, conditions, or experiences about
relocation?
Date: Tue, 25 Jun 2024 16:16:22 +0200
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <v5ejfk$1jcjh$1@raubtier-asyl.eternal-september.org>
References: <v4ojs8$gvji$1@dont-email.me>
<v5e090$1fr82$1@raubtier-asyl.eternal-september.org>
<667accaa$0$2873016$882e4bbb@reader.netnews.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 25 Jun 2024 16:16:21 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="e5f07f45ab734ec04a76043ad492dd64";
logging-data="1684081"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18EMFAoleF0J5UfQlKNqx/Oj/ZRf3BaRdQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:VTbTHmw/QIK7oGs3hukY4ZvE3m0=
In-Reply-To: <667accaa$0$2873016$882e4bbb@reader.netnews.com>
Content-Language: de-DE
View all headers

Am 25.06.2024 um 15:56 schrieb DFS:
> On 6/25/2024 4:48 AM, Bonita Montero wrote:
>> Test this code with your Linux installation. For my installation
>> glibc does all realloc()ations in-place. Really surprising for me.
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> int main()
>> {
>>      void *p = malloc( 0x100000000 );
>>      printf( "%p\n", p );
>>      p = realloc( p, 1 );
>>      printf( "%p\n", p );
>>      malloc( 0x100000000 - 0x10000 );
>>      p = realloc( p, 0x100000000 );
>>      printf( "%p\n", p );
>> }
>
>
> $ gcc -Wall montera_test.c -o mt
> montera_test.c: In function ‘main’:
> montera_test.c:10:9: warning: ignoring return value of ‘malloc’ declared
> with attribute ‘warn_unused_result’ [-Wunused-result]
>    10 |         malloc( 0x100000000 - 0x10000 );
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>

This actually isn't a problem because I just wanted to test if the tail
of the p-block is immediately rezsed so that the next grow can't recycle
the memory. But interestingly all steps are done in-place.

Pages:1234

rocksolid light 0.9.8
clearnet tor