ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/04/12/05:28:06

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
Date: Fri, 12 Apr 2002 11:50:15 +0300
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp AT delorie DOT com
Message-Id: <2593-Fri12Apr2002115014+0300-eliz@is.elta.co.il>
X-Mailer: emacs 21.2.50 (via feedmail 8 I) and Blat ver 1.8.9
In-reply-to: <>
(jlsgarrido AT yahoo DOT com)
Subject: Re: New DJGPP hogs memory (was: I need help)
References: <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>
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

> 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

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.

- Raw text -

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