comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Allocation of local constant arrays
Date: Wed, 19 May 2004 17:16:32 -0400
Date: 2004-05-19T17:16:32-04:00	[thread overview]
Message-ID: <rqudnTNShL0sUzbdRVn-sw@comcast.com> (raw)
In-Reply-To: <c8ft6t$gt9$1@e3k.asi.ansaldo.it>

Davide wrote:
> Hi,
> 
> suppose to have a constant array declared inside a procedure. Suppose to
> perform, inside that procedure, a loop in which the elements of the constant
> array are accessed sequentially until some condition become true.
> My question (i know it's a newbie question...): is the local constant array
> copied into the stack each time the procedure is called or it is allocated
> once and for all in some part of the memory? I'm using AdaMulti compiler.

Some compilers can store such an array in the data segment.  But if you 
care, and copying is an issue, put the array in a library level package.

One of the most powerful optimization "tricks" in Ada is that you can 
put data in in structures  inside library packages that would have to be 
allocate on the heap as in C, or nested inside a procedure or function.

It is sometimes tricky to do all this before the main program executes, 
but it can be done.  And it is great during debugging of mathematical 
packages to be able to read the tables from a file, then compile them 
into the final package when debugging is done.  A good example is the 
inverse normal function.  The best approach is to use different 
(approximation) algorithms for different parts of the function.  It is 
nice to be able to test the various cut-points and interpolation 
constants without recompiling, then put everything as constants in the 
package body.

-- 

                                           Robert I. Eachus

"The terrorists rejoice in the killing of the innocent, and have 
promised similar violence against Americans, against all free peoples, 
and against any Muslims who reject their ideology of murder. Their 
barbarism cannot be appeased, and their hatred cannot be satisfied. 
There's only one way to deal with terror: We must confront the enemy and 
stay on the offensive until these killers are defeated." -- George W. Bush




  parent reply	other threads:[~2004-05-19 21:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-19 15:07 Allocation of local constant arrays Davide
2004-05-19 15:17 ` Davide
2004-05-19 21:16 ` Robert I. Eachus [this message]
2004-05-20  9:56   ` Davide
2004-05-20 11:24     ` Martin Krischik
2004-05-20 18:36       ` Freejack
2004-05-21  9:44         ` Martin Krischik
2004-05-21  2:32     ` Steve
2004-05-21  3:07     ` Robert I. Eachus
replies disabled

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