Deutsch   English   Français   Italiano  
<v5e7m6$1gt2p$3@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Vir Campestris <vir.campestris@invalid.invalid>
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
Bytes: 2100

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.