ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/04/13/07:40:00

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
Message-ID: <20020412182911.49752.qmail@web9904.mail.yahoo.com>
Date: Fri, 12 Apr 2002 11:29:11 -0700 (PDT)
From: Lets Go Canes <letsgonhlcanes AT yahoo DOT com>
Subject: Re: New DJGPP hogs memory (was: I need help)
To: djgpp AT delorie DOT com
In-Reply-To: <5.0.2.1.0.20020411161942.00bd1eb0@pop.mail.yahoo.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

Hello all.

  I realize this was intended as a test program, but on the assumption
that it is based on a real program, I thought I would make a few
comments/suggestions.

--- "José_L._Sánchez_Garrido" <jlsgarrido AT yahoo DOT com> wrote:
> -------------------cut here-----------------------------------
> #include <stdio.h>
> #include <stdlib.h>
> 
> typedef struct {
>      char af[10];
>      char name[10];

    You are going to allocate 2,000,000 of these structures, which will
be ~40MB (plus overhead).  Unless you know that the data being placed
in .af and .name are going to use more than 5 or characters, it *might*
be worth changing these to pointers.  It all depends on the data.

> 
> } 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));
>      }

Surely this should be something like:

#define LIMIT 200000L

       dt=(record **)alloc(dt, LIMIT*sizeof(record *));
       for (count=0; count<LIMIT; count ++)
            dt[count]=(record *)calloc(10, sizeof(record));


Also, do you really intend to allocate an array of 10 "record"s?  If
yes, then shouldn't dt be "record  ***dt"?

>      return(0);
> }
> ------------------cut here---------------------------------------


=====
--------------
Lets Go Canes!

__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

- Raw text -


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