> Yup,
> I used this in (function splitfields) where the delimiter was chosen
> with getopt:
>
>       http://etudiant.epitech.net/~veins/sort/sort.c

Oh yes, sort... that reminds me...

  http://www.gtoal.com/wordgames/sort/sort.[ch]

- see the above for the epitome of managing store yourself...

It's not pretty and I'm not proud of the actual code but I was very
pleased with the way I did the memory management.  It allocates a
single block of RAM at startup and partitions it rather sneakily
for all objects ever needed by the program, I believe as efficiently
as is possible.

I wrote this because we were sorting text files of 100's of Mb on
a machine that had 4Mb of physical ram; gnusort had a serious bug
in that you told it how much ram you wanted to use but it then went
over your request quite significantly.  This was semi-OK on Unix
where the use of VM would at least let the program run (albeit
thrashing VM a lot) but on our hardware with physical memory only,
it *always* failed a malloc at some point.  As has been noted in
this thread, realloc is evil!

The code is well commented. Some might say to excess :-)  It's
probably one of the most complex pieces of memory management I've
had to do in an application, and I didn't want to take the risk 
that I'd have to do maintenance on it 20 years later, and take
one look at it and say "WTF???!"  (So I guess that means it'll
be due for maintenance in 2008 ;-) )

G

Reply via email to