Mail Archives: djgpp/2002/04/12/08:00:13
Eli Zaretskii wrote:
>
> > Date: Thu, 11 Apr 2002 16:25:50 -0500
> > From: =?iso-8859-1?Q?=22Jos=E9_L=2E_S=E1nchez_Garrido=22?=
> > <jlsgarrido AT yahoo DOT com>
> >
> > typedef struct {
> > char af[10];
> > char name[10];
> >
> > } record;
> >
> > record **dt, *d;
> >
> > int main (void) {
> >
> > int count;
> >
> > for(count=0; count<200000L; count++){
> > dt=(record **)realloc(dt, (count+1)*sizeof(record *));
> > d=dt[count];
> > d=(record *)calloc(10, sizeof(record));
> > }
> > return(0);
> > }
>
> Can you please tell what memory consumption did you see with each one
> of the two versions of the compiler and the library?
>
> Also, you don't say what compiler switches did you use to compile and
> link the program.
>
> Anyway, based on looking into this program, I think the changed
> behavior is due to the new version of malloc in libc.a from DJGPP
> v2.03 (so it has nothing to do with the compiler). The program uses a
> very bad algorithm--reallocating an array on each iteration,
> increasing its size by 1. It also allocates the memory in lots of
> very small chunks. So it doesn't surprise me that you run out of free
> memory.
>
> My recommendation is to modify the algorithm to do a better
> allocation. If you cannot do that for some reason, you can find the
> old implementation of malloc in djlsr203.zip, file name
> src/libc/ansi/stdlib/fmalloc.c; link it with your program, and you
> will get the old behavior.
He might also try my suggested new malloc package for DJGPP, which
I have mounted at:
<http://cbfalconer.home.att.net/download/nmalloc.zip>
which, among other things, goes to some pains to minimize the
realloc work. I have heard nothing back on it from anyone, either
good or bad.
--
Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT worldnet DOT att DOT net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
- Raw text -