comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Allocators and exceptions
Date: Wed, 12 Sep 2007 11:32:09 +0200
Date: 2007-09-12T11:26:57+02:00	[thread overview]
Message-ID: <1ww3fzbyqdqfo$.xogsd4dk2cg$.dlg@40tude.net> (raw)
In-Reply-To: 1189537626.913207.116840@e34g2000pro.googlegroups.com

On Tue, 11 Sep 2007 12:07:06 -0700, Maciej Sobczak wrote:

> On 11 Wrz, 14:27, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
> 
>> This error is likely unrecoverable, so you have to reconsider your design
>> which allowed such errors.
> 
> I disagree. The error might be unrecoverable (like broken network
> cable), but might as well be worth retrying with modified parameters
> (like wrong credentials were provided by the user).
> Even in unrecoverable case I might want to gracefully reduce the
> functionality of the system. Sorry, there will be no music today, but
> please enjoy the party anyway - this sort of thing.

Sure, but your design does not allow this. And establishing connection upon
construction is a bad idea anyway.

>> BTW, formally everything is exactly as you wished! Observe, that
>>
>>    new T(-5)
>>
>> creates an object of the type T_Access. This object does not come to
>> existence and the compiler carefully eliminates any traces of this object.
>> Everything is fine!
> 
> Except of the memory leak and the already created other components.

Which is not T_Access's business.

>> What you actually want, but didn't say it, is that T_Access would take care
>> of the things it points to, so its constructor (new) would.
> 
> No. T_Access is not (yet) involved. This has to be handled entirely by
> the allocator, because the whole problem happens even before T_Access
> is assigned to my access variable.

"new" is a method of T_Access, it is not of T. That's the whole point. You
want some intimate relations between T_Access and T. But there is no
unified way to define them. The language offers you only raw pointers. you
have to add some meat to these pointers. The gears Ada has for this job are
quite rudimentary, namely ad-hoc polymorphism (overloaded subprograms). Not
much. If T_Access had a user-defined constructor, you could handle
deallocation of target there upon exception propagation. But it does not.

>>> This is what allows me to keep abstractions and invariants: either I
>>> have the complete object with its guaranteed invariants, or there is
>>> nothing. Anything in between is mess.
>>
>> This is violated upon aggregation of initialized components with side
>> effects. I don't argue that this is good, I only state that this is the
>> current language design and that it would be quite challenging to alter.
> 
> I understand that it cannot be changed. At least not shortly after the
> last standardization iteration. :-)
> 
> But... did I mention that C++ handles this issue correctly? ;-)
> And no, it does not have any super-capable access types. A little bit
> smarter allocator is enough.

Really?

class Foo
{
   Baz * A;
   Bar * B;

   Foo () : A (new Baz), B (new Bar) { ... throw ... }

If initialization of B fails, A will not be freed. After execution of
throw, neither A nor B will be freed. C++ does not handle it correctly, it
just does it a bit less incorrect. (:-))

Ada lacks a consistent unified construction model (one for *all* types).

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2007-09-12  9:32 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 [this message]
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
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