Deutsch   English   Français   Italiano  
<v5ejfk$1jcjh$1@raubtier-asyl.eternal-september.org>

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

Path: ...!feed.opticnetworks.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita Montero <Bonita.Montero@gmail.com>
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
Bytes: 2416

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.