www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/04/13/12:30:26

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
Message-ID: <3CB8548A.5B103D60@yahoo.com>
From: CBFalconer <cbfalconer AT yahoo DOT com>
Organization: Ched Research
X-Mailer: Mozilla 4.75 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: New DJGPP hogs memory (was: I need help)
References: <20020412182911 DOT 49752 DOT qmail AT web9904 DOT mail DOT yahoo DOT com>
Lines: 51
Date: Sat, 13 Apr 2002 16:15:00 GMT
NNTP-Posting-Host: 12.90.169.231
X-Complaints-To: abuse AT worldnet DOT att DOT net
X-Trace: bgtnsc05-news.ops.worldnet.att.net 1018714500 12.90.169.231 (Sat, 13 Apr 2002 16:15:00 GMT)
NNTP-Posting-Date: Sat, 13 Apr 2002 16:15:00 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Lets Go Canes wrote:
> 
>    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.

There is more than that wrong with it.  A cleaned up version
follows:

/* From djgpp mail list - an evil algorithm */
/* This shows up the difference between DJGPP2.03 malloc and
   nmalloc, both in speed and in efficiency of memory use.
   Snaffled/cleaned up for testing use by C.B. Falconer.

   To use the new malloc, simply link it with the object module.
*/
#include <stdio.h>
#include <stdlib.h>

typedef struct {
   char af[10];
   char name[10];
} record;

record **dt, *d;

int main(int argc, char ** argv)
{
   unsigned long n = 1000;  /* was 200000L */
   unsigned int  count;
   void         *v;

   if (argc > 1) n = strtoul(argv[1], NULL, 10);

   dt = NULL;
   for (count = 0; count < n; count++){
      if ((v = realloc(dt, (count + 1) * sizeof *dt))) dt = v;
      else break;
      if (!(d = dt[count] = calloc(10, sizeof *d))) break;
      if (!(count & 0xfff)) putc('*', stderr);
   }
   printf("\ncount=%d\n", count);
   return(0);
} /* evilalgo */

-- 
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 -


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