comp.lang.ada
 help / color / mirror / Atom feed
From: "Bradley A. Burns" <bburns@usa.net>
Subject: Re: Help you C++ Debuggers!
Date: 1997/01/21
Date: 1997-01-21T00:00:00+00:00	[thread overview]
Message-ID: <01bc07b5$1c546820$79ceaec7@sprynet.com> (raw)
In-Reply-To: OHK.97Jan21093610@ultra.tfdt-o.nta.no


This type of data capsule in C++ would best be declared dynamically. Look
into the standard NEW and DELETE operators. You will need to use type
pointers but that's not a problem at all.

For example:
	float* f_var = new float[9000];

This will dynamically allocate an array of 9000 floats. You access these by
using the standard array reference notation, for example:

	float f_temp = f_var[1280];
	// returns 1 float value at array index 1280.
	// (actually 1279) since the index is 0 based.

...and remember, you can delete this singular array in one easy step:

	delete[] f_var;

Now, all you have to do is apply it to a 3 dimensional array. By the way,
the way you are doing it below, with some (most?) C++ compilers, even the
smart ones, will reserve actual space in the .EXE file for 900,000 floats,
therefore making your application much larger than it has to be, both in
memory and on the hard disk. One other advantage of dynamic allocations is,
say your application has many different areas (modules?) and you only need
that large array of floats for one of those modules, you can perform a
delete[] when the user leaves that module to go into another one. This, of
course, is assuming that you're allocating these 900,000 locally (allocated
and used only within a specific function or class), but somehow I think
that this array is being allocated globally, for the entire application.

Hope this helps,
Brad.

Ole-Hjalmar Kristensen FOU.TD/DELAB <ohk@ultra.tfdt-o.nta.no> wrote in
article <OHK.97Jan21093610@ultra.tfdt-o.nta.no>...
> In article <1997Jan20.144447.5581@news>
Gautier.DeMontmollin@maths.unine.ch (Gautier) writes:
> 
>    Macarthur Drake <drake@bme.ri.ccf.org> writes:
>    > I am in the mist of completing a major piece of code in C++. However
I
>    > keep comming across a particularly difficult bug. Can you help?
>    > 	
>    > 	I am simply trying to declare a three D array:
>    > 
>    > 
>    > float objects[9000][10][10];
>    > 
>    > 	However, sometimes while compiling I get a strange compilation
error
>    > like one of the following:
>    > 
>    > 1. segmentation violation
>    >
>    The C compilers are known to have problems with multi-dim arrays.
>    Remember that C is near to a macro assembler (-> segmentation...)!
>    Remedy:
> 
> You must use some pretty strange C compilers.....
> 
>    1. 
>       Make an 1-dim array and handle the 3 dims with multiplications
> 
> Download gcc if your C compiler is broken.
> 
>    2.
>       Download a good Ada compiler... N.B.: your message was posted in
>       comp.lang.ada . Was it premonitory ? ;)-
> 
> Yes.
> 




  reply	other threads:[~1997-01-21  0:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-16  0:00 Help you C++ Debuggers! Macarthur Drake
1997-01-19  0:00 ` Tore Lund
     [not found]   ` <32E4EC1B.748E@acm.org>
1997-01-23  0:00     ` Tansel Ersavas
1997-01-23  0:00       ` Tansel Ersavas
1997-01-23  0:00       ` Danette & Murray Root
     [not found]       ` <01bc093e$9992fa60$966d6f9e@Defualt.DVRD.CDC.GOV>
1997-01-24  0:00         ` Tore Lund
1997-01-25  0:00         ` Lawrence Kirby
1997-01-20  0:00 ` Gautier
1997-01-20  0:00   ` Tanmoy Bhattacharya
1997-01-21  0:00   ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-01-21  0:00     ` Bradley A. Burns [this message]
1997-01-21  0:00   ` Chris Engebretson
1997-01-21  0:00   ` Chris Engebretson
1997-01-21  0:00   ` David Emery
1997-01-22  0:00   ` Michael Chapman
1997-01-22  0:00   ` David Emery
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox