Sujet : Re: realloc() - frequency, conditions, or experiences about relocation?
De : anton.txt (at) *nospam* g{oogle}mail.com (Anton Shepelev)
Groupes : comp.lang.c sci.stat.mathDate : 08. Jul 2024, 19:01:21
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240708200121.ec07d0338a336b56cc7387a1@g{oogle}mail.com>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
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