Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Anton Shepelev Newsgroups: comp.lang.c,sci.stat.math Subject: Re: realloc() - frequency, conditions, or experiences about relocation? Date: Mon, 8 Jul 2024 20:01:21 +0300 Organization: A noiseless patient Spider Lines: 51 Message-ID: <20240708200121.ec07d0338a336b56cc7387a1@g{oogle}mail.com> References: <875xu8vsen.fsf@bsb.me.uk> <87zfrjvqp6.fsf@bsb.me.uk> <20240617180249.96dfaafa89392827aa162434@g{oogle}mail.com> <87le2kwf9z.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Date: Mon, 08 Jul 2024 19:01:23 +0200 (CEST) Injection-Info: dont-email.me; posting-host="46dbe6ab9786220f9431ea65e0802f88"; logging-data="1007462"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18FwxAQMrpwlRqIwz5fQ80rA1c4bQy3OIQ=" Cancel-Lock: sha1:LJR3g9+jFTuuioYdV0vD2kR8Yw4= X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Bytes: 3390 Rich Ulrich: > Thanks, so it looks like a failure by GigaNews to retrieve > the recent posts. > > I did see a bunch of cross-posted followups. I don't know > C, and I thought there could be more context. Characters are being read in (say, from a file) sequentially and stored in computer memory (RAM) in an "array" -- a linear data structure storing elements (our characters) in a sequential order, one ofter the other at addresses with increasing indexes -- somewhat like a mathematical vector. In order to store a character in an array, sufficient memory has to be "allocated" for it, but while reading we do not know beforehand the size of the file (or the total length of the sequence), and therefore increase the allocated aray size prospectively once the previous allocation is filled. This operaion is called `realloc' and frequently involves the tedious copying of the entire array onto a new location in memory, taking a time in proportion to the number elemennts so far allocated. The question is to develop an optimal allcation strategy for a given distribution of file sizes. The fasted solution is to allocate a gigantic array beforehand, but it is a terrible waste of memory. The slowet solution is to reallcoate for each single character read it, but is a terrible waste of CPU time. As I understand the problem, a strategy is needed that manifests some compromise between the extremes. > Looking at original, absent posts is something I've done > dozens of times over the years. Never a problem, except > fora time or two with posts from the 1990s. I've used > GigaNews since my regular ISP stopped providing Usenet > access, maybe 15 years ago. Just in case, there are many totally free Usenet servers, e.g.: http://www.eternal-september.org/ https://www.i2pn2.org/ and even a web interface: https://www.novabbs.com -- () ascii ribbon campaign -- against html e-mail /\ www.asciiribbon.org -- against proprietary attachments