Mail Archives: djgpp/2002/04/12/09:54:07
At 11:50 12/04/2002 +0300, you 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?
Oops, I'm very, very sorry.
With gcc 2.81 and djdev201, this innocent loop takes ~52 MB, and run in <1
s. in a PII at 500 Mhz, 128 MB Ram, whereas with gcc 2.95.3 and djdev203,
on same machine, the memory is exhausted at 70,000L iterations.
>Also, you don't say what compiler switches did you use to compile and
>link the program.
I compile and link without optimizations, and with debug information, and
tracing in RHIDE, i.e.:
gcc -o test.exe -g test.c
>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.
Well..., you have a point, the algorithm is very bad. However, this
algorithm works fine with djdev201, and this is the reason because I post
the problem to the group. As I say in the first post, my english is so bad,
and I apologize if I'm not so clear.
By another way, I modify the program to call malloc (or calloc) previously
to the loop, and without call realloc inside, and there are no problem with
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.
Thanks a lot for your time and help.
JL.
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
- Raw text -