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 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: References: 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: 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 > #include > > 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.