Path: ...!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Lawrence D'Oliveiro Newsgroups: comp.lang.c Subject: Re: realloc() - frequency, conditions, or experiences about relocation? Date: Mon, 24 Jun 2024 08:40:03 -0000 (UTC) Organization: A noiseless patient Spider Lines: 14 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 24 Jun 2024 10:40:05 +0200 (CEST) Injection-Info: dont-email.me; posting-host="3048fea01d51f9337586ac8e02824e6c"; logging-data="902488"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+em28bzjCK4Sv7usPscyL" User-Agent: Pan/0.158 (Avdiivka; ) Cancel-Lock: sha1:MQTEmnDn1hgbSZ9BNO+Fi9zKdls= Bytes: 1802 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 ...