comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Allocators and exceptions
Date: Wed, 12 Sep 2007 22:42:27 -0500
Date: 2007-09-12T22:42:27-05:00	[thread overview]
Message-ID: <fcabdr$d1o$1@jacob-sparre.dk> (raw)
In-Reply-To: m2abrro3f0.fsf@mac.com

"Simon Wright" <simon.j.wright@mac.com> wrote in message
news:m2abrro3f0.fsf@mac.com...
> "Randy Brukardt" <randy@rrsoftware.com> writes:
...
> > The "proper" way to handle this is to ensure that default initialize
> > of an object never propagates an exception, and then wrap the
> > allocator properly:
> >
> >     type Access_T is access all T;
> >     procedure Free is new Unchecked_Deallocation (T, Access_T);
> >     function Alloc_Object (...) return Access_T is
> >        A_T : Access_T := new T; -- Default initialized.
> >     begin
> >        A_T.all := <constructor>;
> >        return A_T;
> >     exception
> >         when others => Free(A_T); return null;
> >     end Alloc_Object;
>
> I guess I had misunderstood what's meant by 'constructor', becasue
> this is just what I had in mind ... and there are far worse things to
> leak than memory, such as locks, file handles, data structure
> integrity etc, and those we can handle even in a constructor (ie
> function returning a value of the type rather than a pointer to a new
> value of the type).

The problem with this sort of construction (besides that it is clunky) is
that is doesn't work for limited types without breaking abstraction. OTOH,
the leak in this case doesn't bother me too much, because constructor
failure ought to be rare and it is also rare to be creating a lot of
objects -- so it usually doesn't matter. Moreover, safety critical
applications aren't going to be using allocators in the first place, and
very long-running applications are likely to have problems with memory
fragmentation even if they don't leak any memory -- unless they have a lot
more memory available than they're going to need. Still, the leak is
uncomfortable - it doesn't match Ada's goals.

                 Randy.





  reply	other threads:[~2007-09-13  3:42 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-09  7:40 Allocators and exceptions Maciej Sobczak
2007-09-09 12:17 ` anon
2007-09-09 20:31   ` Maciej Sobczak
2007-09-09 22:43     ` Simon Wright
2007-09-10 12:10       ` Maciej Sobczak
2007-09-10 19:08         ` Simon Wright
2007-09-10  2:56     ` anon
2007-09-10 12:42     ` Dmitry A. Kazakov
2007-09-10 21:48       ` Maciej Sobczak
2007-09-11  9:16         ` Dmitry A. Kazakov
2007-09-11  9:19           ` Maciej Sobczak
2007-09-11 12:27             ` Dmitry A. Kazakov
2007-09-11 19:07               ` Maciej Sobczak
2007-09-11 22:56                 ` Georg Bauhaus
2007-09-12 12:36                   ` Maciej Sobczak
2007-09-12 22:19                     ` Randy Brukardt
2007-09-12  9:32                 ` Dmitry A. Kazakov
2007-09-12 12:42                   ` Maciej Sobczak
2007-09-12 15:25                     ` Dmitry A. Kazakov
2007-09-12 12:29             ` Stephen Leake
2007-09-12 12:46               ` Maciej Sobczak
2007-09-12 20:53                 ` Simon Wright
2007-09-12 22:32                   ` Randy Brukardt
2007-09-12 23:43                     ` Simon Wright
2007-09-13  3:42                       ` Randy Brukardt [this message]
2007-09-13  3:36                     ` Randy Brukardt
2007-09-13  9:43                     ` Maciej Sobczak
2007-09-12 22:25                 ` Randy Brukardt
2007-09-13 11:51                 ` Stephen Leake
2007-09-12 14:14               ` Markus E L
2007-09-10 10:37 ` Allocators and exceptions => Read Me First anon
2007-09-10 12:16   ` Maciej Sobczak
2007-09-10 22:10     ` Allocators and exceptions => Trying Again anon
2007-09-10 23:15       ` Markus E L
2007-09-10 15:44 ` Allocators and exceptions Adam Beneschan
2007-09-10 21:58   ` Maciej Sobczak
2007-09-10 22:07   ` Jeffrey R. Carter
2007-09-11  9:14   ` Dmitry A. Kazakov
2007-09-11  9:23     ` Maciej Sobczak
2007-09-11  2:36 ` Randy Brukardt
2007-09-11 15:33   ` Adam Beneschan
2007-09-11 19:21     ` Maciej Sobczak
2007-09-11 21:56     ` Adam Beneschan
2007-09-12  0:34       ` Jeffrey R. Carter
2007-09-12 12:13         ` Maciej Sobczak
2007-09-12 16:34           ` Jeffrey R. Carter
2007-09-12 23:50             ` Jeffrey R. Carter
2007-09-12 12:22       ` Maciej Sobczak
2007-09-12 14:11         ` Markus E L
2007-09-12 16:08         ` Adam Beneschan
2007-09-12 20:35           ` Dmitry A. Kazakov
2007-09-12 21:01             ` Adam Beneschan
2007-09-12 22:45             ` Randy Brukardt
2007-09-13  7:48               ` Dmitry A. Kazakov
2007-09-12  3:08 ` Allocators and exceptions -- Debugging says memory leak! anon
replies disabled

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