comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: memory management in Ada: tedious without GC?
Date: Fri, 16 May 2008 13:42:15 -0700 (PDT)
Date: 2008-05-16T13:42:15-07:00	[thread overview]
Message-ID: <9f2c2db4-d6c1-4cdf-884c-5cbc26ac7701@d1g2000hsg.googlegroups.com> (raw)
In-Reply-To: 4ddef8bf-b5b1-4d7e-b75b-386cd6c8402c@l17g2000pri.googlegroups.com

On 16 Maj, 19:44, "jhc0...@gmail.com" <jhc0...@gmail.com> wrote:

> As I understood from reading the Memory Management section of
> Wikibooks on Ada, Ada's memory management facilities are roughly
> equivalent to
>
> a. C++-like "new"

Yes, you can do this in Ada.

> b. C++-like "delete"

Yes, you can do this in Ada, but it is discouraged by the awful syntax
and actually rarely needed.

> c. Java-like "finally"

I don't see any equivalent to "finally" in Ada - and, as in C++, it is
not needed, since a superior tool is available: RAII.

> d. your implementation may or may not have GC

Just as in C++. In practice and for portability it means: assume there
is no GC.

> Did I misunderstand?

Actually, Ada and C++ are very similar in this regard and Java differs
widely from these two.

> To me, this seems much, much more error-prone and tedious that C++'s
> RAII approach

In Ada RAII is realized with controlled types. They are severely
broken in that they are intrusive in the type hierarchy and they burn
the whole budget for implementation inheritance, which is a big issue
with the lack of multiple inheritance (controlled streams, anyone?) -
these problems don't exist in C++ - but apart from that both Ada and C+
+ represent a similar approach to resource management. You *can* have
RAII-enabled files, database sessions, smart pointers, and so on.

Note that Ada, even though provides the possibility to use RAII when
designing types, does not benefit from it everywhere in its standard
library.

> where you almost never have to worry about deallocation
> (i.e. "b" and "c" above), even in the presence of exceptions, unless
> you have GC.

> Besides, RAII applies to a bunch of other things, like
> thread locks, database connections, files - not just memory.

That's why GC should not stop you from worrying about resources (and
if you still have to worry, then what's the fuss?). The above are
resources, which are not correctly addressed by GC as you know it from
Java.
Compared to this, RAII is a more uniform framework for handling
resources *in general* and both Ada and C++ support it.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com



  parent reply	other threads:[~2008-05-16 20:42 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-16 17:44 memory management in Ada: tedious without GC? jhc0033
2008-05-16 18:56 ` Ludovic Brenta
2008-05-16 20:42 ` Maciej Sobczak [this message]
2008-05-16 21:45   ` Ivan Levashew
2008-05-16 22:59   ` Peter C. Chapin
2008-05-17  5:24     ` jhc0033
2008-05-17  7:50       ` Ivan Levashew
2008-05-16 23:05   ` Randy Brukardt
2008-05-19  3:50   ` Matthew Heaney
2008-05-19  7:55     ` Dmitry A. Kazakov
2008-05-19 13:18       ` Georg Bauhaus
2008-05-19 14:16         ` Dmitry A. Kazakov
2008-05-23 23:15       ` Robert A Duff
2008-05-24  0:45         ` Randy Brukardt
2008-05-24  8:25         ` Dmitry A. Kazakov
2008-05-24 16:14           ` Robert A Duff
2008-05-24 19:04             ` Dmitry A. Kazakov
2008-05-24 20:52               ` Robert A Duff
2008-05-25  8:12                 ` Dmitry A. Kazakov
2008-05-25 11:28                   ` Maciej Sobczak
2008-05-25 12:35                   ` Robert A Duff
2008-05-26  8:16                     ` Dmitry A. Kazakov
2008-05-24 19:39             ` Georg Bauhaus
2008-05-24 20:45               ` Robert A Duff
2008-05-19  8:35     ` Maciej Sobczak
2008-05-19 15:11       ` Matthew Heaney
2008-05-19 21:13         ` Maciej Sobczak
2008-05-23 23:03         ` Robert A Duff
2008-05-24  0:12           ` Adam Beneschan
2008-05-16 22:45 ` anon
2008-05-17  7:34 ` Pascal Obry
2008-05-17 15:11   ` Bob Klungle
2008-05-17 15:27     ` Pascal Obry
2008-05-17 16:18       ` Georg Bauhaus
2008-05-20  8:04         ` Ole-Hjalmar Kristensen
2008-05-20  8:01       ` Ole-Hjalmar Kristensen
2008-05-20 10:03         ` Martin Krischik
2008-05-17 17:23     ` Martin Krischik
2008-05-17 16:51   ` Maciej Sobczak
2008-05-17 17:45     ` Pascal Obry
2008-05-17 22:28       ` Samuel Tardieu
2008-05-18  7:03         ` Martin Krischik
2008-05-18  8:50           ` jhc0033
2008-05-18  9:31             ` Dmitry A. Kazakov
2008-05-18 14:10               ` Maciej Sobczak
2008-05-18 14:59                 ` Dmitry A. Kazakov
2008-05-18 20:51                   ` Maciej Sobczak
2008-05-19  8:36                     ` Dmitry A. Kazakov
2008-05-18 15:03             ` Martin Krischik
2008-05-18 18:27               ` jhc0033
2008-05-19  4:12                 ` Matthew Heaney
2008-05-19  8:39                   ` Maciej Sobczak
2008-05-19 15:37                     ` Matthew Heaney
2008-05-19 21:21                       ` Maciej Sobczak
2008-05-19 23:02                         ` Matthew Heaney
2008-05-19 10:27                 ` Martin Krischik
2008-05-17 22:42       ` Peter C. Chapin
2008-05-18  6:58         ` Martin Krischik
2008-05-18  6:52     ` Martin Krischik
2008-05-18 14:16       ` Maciej Sobczak
2008-05-17 14:30 ` Brian Drummond
2008-05-17 16:47   ` Maciej Sobczak
2008-05-19 14:45     ` Brian Drummond
2008-05-20  7:42       ` Maciej Sobczak
2008-05-20 18:01         ` jayessay
2008-05-18  8:06   ` Simon Wright
2008-05-18 14:21     ` Maciej Sobczak
2008-05-18 20:48       ` Simon Wright
2008-05-19 14:40     ` Brian Drummond
2008-05-19  3:44 ` Matthew Heaney
replies disabled

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