comp.lang.ada
 help / color / mirror / Atom feed
From: robert_dewar@my-dejanews.com
Subject: Re: How do I get this to work??
Date: 1999/01/16
Date: 1999-01-16T00:00:00+00:00	[thread overview]
Message-ID: <77q5m8$e4o$1@nnrp1.dejanews.com> (raw)
In-Reply-To: GIVn2.8028$Kg6.59441@news2.telusplanet.net

In article <GIVn2.8028$Kg6.59441@news2.telusplanet.net>,
  warwicks@telusplanet.net (Chris Warwick) wrote:
> Even from my Ada83 days, the only "safe" way to do
> dynamic memory allocation was though the use of local
> variables on the stack. If I understand this concept,
> then the view is that it is better to point to a newly
> allocated buffer, then it is to point to a procedure's
> local variable.

Exactly, and the reason is to avoid aliasing. This is a
very familiar principle. Look at Pascal for example to
see the start of this thread of design thinking, which Ada
adopted. Ada 95 adds aliased variables, but they should be
used with discretion!

> Given that most Ada compilers have no way to deallocate
> memory,

That's simply wrong. Both Ada 83 and Ada 95 have a way
to deallocate dynamic memory (Unchecked_Deallocation), and
an Ada compiler not implementing this facility is
impossible to imagine (and has never existed).

> I seem to be trading the potential for a pointer to exist
> past the life of the allocated memory for a program
> continously allocates memory...

Not clear what you are saying here. Certainly pointing
to local variables on the stack has very dangerous possible
consequences with regard to dangling pointers.

The point here is that if you look at any program that
uses the keyword ALIASED extensively, then this is almost
always an example or importing C style into Ada (see
separate thread on importing Pascal into COBOL :-) and is
something that should be avoided. Almost always such code
can be written to avoid the use of ALIASED, and the result
will be improved, better structured code.

Robert Dewar

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




  reply	other threads:[~1999-01-16  0:00 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-01-04  0:00 How do I get this to work?? Chris Warwick
1999-01-05  0:00 ` Chris Warwick
1999-01-05  0:00   ` Stephen Leake
1999-01-05  0:00     ` Tom Moran
1999-01-06  0:00       ` robert_dewar
1999-01-06  0:00         ` Tom Moran
1999-01-07  0:00           ` robert_dewar
1999-01-07  0:00             ` Tom Moran
1999-01-10  0:00               ` robert_dewar
1999-01-06  0:00         ` Larry Kilgallen
1999-01-06  0:00           ` Tom Moran
1999-01-06  0:00         ` Tom Moran
1999-01-07  0:00           ` robert_dewar
1999-01-07  0:00             ` Tom Moran
1999-01-10  0:00               ` robert_dewar
1999-01-10  0:00                 ` Tom Moran
1999-01-10  0:00                   ` robert_dewar
1999-01-10  0:00                     ` Tom Moran
1999-01-10  0:00                     ` Pat Rogers
1999-01-10  0:00                   ` robert_dewar
1999-01-06  0:00     ` robert_dewar
1999-01-06  0:00     ` Chris Warwick
1999-01-06  0:00       ` Tom Moran
1999-01-07  0:00       ` robert_dewar
1999-01-09  0:00         ` Chris Warwick
1999-01-09  0:00           ` Simon Wright
1999-01-10  0:00             ` robert_dewar
1999-01-11  0:00               ` Simon Wright
1999-01-16  0:00               ` Chris Warwick
1999-01-16  0:00                 ` robert_dewar [this message]
1999-01-18  0:00                   ` Chris Warwick
1999-01-18  0:00                     ` Matthew Heaney
1999-01-16  0:00                 ` Simon Wright
1999-01-16  0:00                 ` Matthew Heaney
1999-01-16  0:00                   ` robert_dewar
1999-01-18  0:00                   ` Chris Warwick
1999-01-18  0:00                     ` Matthew Heaney
1999-01-18  0:00                     ` dennison
1999-01-18  0:00                     ` robert_dewar
1999-01-18  0:00                       ` dennison
1999-01-18  0:00                       ` Tucker Taft
1999-01-19  0:00                         ` Chris Warwick
1999-01-19  0:00                           ` robert_dewar
1999-01-20  0:00                             ` Jeff Carter
1999-01-20  0:00                               ` robert_dewar
1999-01-21  0:00                                 ` Chris Warwick
1999-01-19  0:00                           ` Stephen Leake
1999-01-19  0:00                           ` Tom Moran
1999-01-09  0:00           ` Brian Rogoff
1999-01-10  0:00             ` Matthew Heaney
1999-01-07  0:00       ` Stephen Leake
1999-01-08  0:00         ` Simon Wright
1999-01-06  0:00   ` Simon Wright
1999-01-22  0:00   ` Nick Roberts
1999-01-05  0:00 ` Tom Moran
replies disabled

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