delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/11/11/05:30:35

Date: Tue, 11 Nov 1997 12:15:51 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: John Machin <sjmachin AT lexicon DOT net DOT au>
cc: djgpp-workers AT delorie DOT com
Subject: Re: malloc()
In-Reply-To: <9711102035.AA14775@clio.rice.edu>
Message-ID: <Pine.SUN.3.91.971111121512.16499A-100000@is>
MIME-Version: 1.0

On Mon, 10 Nov 1997, Charles Sandmann wrote:

> > > pathalogical data initialization codes to see how they perform in
> > What are these, please?
> 
> There were some examples discussed on the NG/Mailing list about a month
> back, in which the initialization of an array with a large number of
> elements consumed a huge amount of memory.  I would suggest checking the
> mailing list archives - I don't remember the details.

Here's a source that reveals this problem.

Please note that this source causes a lot of allocations, but I'm not
sure it also causes a lot of calls to realloc/free.

Also note that the actual source is 300K and I didn't want to post it
in its entirety.  You will have to replicate the lines that initialize
the array with your favorite editor or another tool.

#include <stdio.h>
#include <stdlib.h>

unsigned xxx[100000] = {
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  /* there should be 10,000 lines like this */
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
};

int main (void)
{
  return printf ("%d\n", xxx[rand() % 3] + xxx[rand() % 4]);
}

- Raw text -


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