delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/04/12/09:54:07

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
Message-Id: <5.0.2.1.0.20020412081423.00bb4bc0@pop.mail.yahoo.com>
X-Sender: jlsgarrido AT pop DOT mail DOT yahoo DOT com
X-Mailer: QUALCOMM Windows Eudora Version 5.0.2
Date: Fri, 12 Apr 2002 08:51:13 -0500
To: djgpp AT delorie DOT com
From: =?iso-8859-1?Q?=22Jos=E9_L=2E_S=E1nchez_Garrido=22?=
<jlsgarrido AT yahoo DOT com>
Subject: Re: New DJGPP hogs memory (was: I need help)
In-Reply-To: <2593-Fri12Apr2002115014+0300-eliz@is.elta.co.il>
References: <5 DOT 0 DOT 2 DOT 1 DOT 0 DOT 20020411161942 DOT 00bd1eb0 AT pop DOT mail DOT yahoo DOT com>
<5 DOT 0 DOT 2 DOT 1 DOT 0 DOT 20020410122845 DOT 00bcbbd8 AT pop DOT mail DOT yahoo DOT com>
<5 DOT 0 DOT 2 DOT 1 DOT 0 DOT 20020410122845 DOT 00bcbbd8 AT pop DOT mail DOT yahoo DOT com>
<5 DOT 0 DOT 2 DOT 1 DOT 0 DOT 20020411161942 DOT 00bd1eb0 AT pop DOT mail DOT yahoo DOT com>
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019