www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/11/05:44:54

Message-ID: <316CE14F.5DDE@matrust.es>
Date: Thu, 11 Apr 1996 11:39:11 +0100
From: Jesus Canal <jesus AT matrust DOT es>
Organization: Digital Illusion (Grup Matrust)
MIME-Version: 1.0
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
CC: djgpp AT delorie DOT com
Subject: Re: malloc crash
References: <Pine DOT SUN DOT 3 DOT 91 DOT 960411075722 DOT 27263C-100000 AT is>

Eli Zaretskii wrote:
> Btw, allocating 5000 chunks of 10KB is a symptom of a very
> memory-inefficent program (IMHO).  If a program indeed needs so many
> allocations, it should allocate memory in a few large chunks and then
> overload `new' with something that serves allocations off those chunks.
> 

I implemented a ZBuffer class as:

   (...)

   int      theHeight;
   int      theWidth;
   double **theArray

   (...)


The constructor allocated one (double *) array, theWidth items long,
and then theWidth double arrays, theHeight items long.
Then accessing the element (X, Y) was theArray [X][Y].


I will try to avoid the malloc crash using only a double * array:

   (...)

   int      theHeight;
   int      theWidth;
   double  *theArray
 
   (...)

and accessing the element (X,Y) as theArray [theWidth * Y + X]

Thank you.

Jesus.

 
--------------------------------------------------------------------------------
                                                DIGITAL ILLUSION * Grup Matrust
      Jesus Canal             Trav. de les Corts, 222 * 08028 Barcelona (Spain)
   Software Enginner               Tel. (34-3) 409 01 15 * Fax (34-3) 409 01 16
                                mailto:jesus AT matrust DOT es * http://www.matrust.es
--------------------------------------------------------------------------------

- Raw text -


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