Deutsch English Français Italiano |
<v54jac$3a4p2$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: Fri, 21 Jun 2024 21:12:12 +0200 Organization: A noiseless patient Spider Lines: 26 Message-ID: <v54jac$3a4p2$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> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 21 Jun 2024 21:12:12 +0200 (CEST) Injection-Info: raubtier-asyl.eternal-september.org; posting-host="cc301cc675ded9210432743989896874"; logging-data="3478306"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19D+HENybx+FHKjDVNW7ySBRafMVHmFtdA=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:rI1CbtzoyeaUZZNlvnBL9yf1XZc= Content-Language: de-DE In-Reply-To: <v52270$2nli8$1@dont-email.me> Bytes: 2499 Am 20.06.2024 um 22:08 schrieb Vir Campestris: > On 17/06/2024 10:22, Bonita Montero wrote: >> >> realloc() is just a convenience funciton. Usually the reallocation >> can't happen in-place and a second malloc() followed by a copy and >> a free() does the same. >> For large data it would be nice if the pages being deallocated later >> would be incrementally marked as discardable after copying a portion. >> This would result in only a small portion of additional physical >> memory being allocated since the newly allocated pages become asso- >> ciated with phyiscal pages when they're touched first. Windows has >> VirtualAlloc() with MEM_RESET for that, Linux has madvise() with >> MADV_DONTNEED. > > "Usually can't happen in place"? Usually you don't resize the block with a few bytes and if you have a large memory area it's unlikely that you can allocate a few additional pages in-place. C++23 has a nice function with the allocator interface called allocate _at_least. It returns the pointer to the allocated memory with the size actually allocated. This fits with modern allocators like mimalloc, je- malloc or tcmalloc, which round up the allocation to the next 2 ^ N boundary up to 8kB. So a vector's capacity directly includes the blend.