comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: access types
Date: Mon, 2 Jul 2007 10:06:28 +0200
Date: 2007-07-02T10:03:19+02:00	[thread overview]
Message-ID: <w0899zqh8cfv.15s3r7qob3dpr.dlg@40tude.net> (raw)
In-Reply-To: wccejjr64uw.fsf@shell01.TheWorld.com

On Sun, 01 Jul 2007 20:12:23 -0400, Robert A Duff wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> On Sun, 01 Jul 2007 10:57:17 -0400, Robert A Duff wrote:
>>
>>> Access-to-classwide should normally use "all".
>>> In fact, you won't go too far wrong if you always say "all"
>>> for all named access-to-variable types.
>>
>> I appreciate storage pools too much to agree with that. There are so many
>> interesting things we can do with pools, multiple inheritance for example!
>> (:-))
> 
> OK, I'll bite.  ;-)
> 
> How do you do multiple inheritance with pools?

Normally one would emulate MI with a mix-in:

type M (Base1 : access B1; Base2 : access B2) is new B3 with private;

The idea is to allocate M in a user pool. The pool would route Allocate and
Deallocate to the standard pool, but doing that Allocate would also reserve
some space for the instances of B1 and B2 in front of the object. M becomes
a pointer. Discriminants can eventually be removed if there is a way to
determine the addresses of B1 and B2 from a pointer (address) to B3.

This is of course a poor man's MI. But it works nicely for some things. For
example I used it for multiple doubly-linked lists of anything. An object
can stay in as many lists one could wish. For each list a record with Prev
and Next pointers is added when the object gets allocated in the pool.
Items of lists are accessed via plain access type, no further redirection
needed, no problem with unconstrained arrays as list items. Write "new
Thing", and the work is done.

> Anyway, "all" does not stop you from using pools.

In some cases it does. access all T is sort of doubly-dispatching. One of
its classes is T'Class, another is Root_Storage_Pool'Class.

The problem is that the second class is not available. We cannot define new
primitive operations which would dispatch on the pointer according to the
specific pool. Only Allocate and Deallocate would.

>> I could never understand why explicit conversion is not allowed for
>> pointers from the same pool.
> 
> Well, that might make sense, but we never thought of that.
> "Pool specific" is somewhat of a misnomer.  It really just
> means "Ada 83-style access type".

They fit nicely into Ada's OO model, as I described above. Maybe it was an
unexpected by-product. Which shows the strength of Ada's fundamentals.

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



  reply	other threads:[~2007-07-02  8:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-01  0:39 access types Brian May
2007-07-01  1:54 ` Robert A Duff
2007-07-01  7:52   ` Dmitry A. Kazakov
2007-07-01 14:57     ` Robert A Duff
2007-07-01 19:41       ` Dmitry A. Kazakov
2007-07-02  0:12         ` Robert A Duff
2007-07-02  8:06           ` Dmitry A. Kazakov [this message]
2007-07-02 15:37       ` Adam Beneschan
  -- strict thread matches above, loose matches on Subject: below --
1999-07-15  0:00 Access Types Ronald Ayoub
1999-07-21  0:00 ` Robert A Duff
1999-07-22  0:00   ` Steve Folly
1999-07-23  0:00     ` Tucker Taft
1998-05-27  0:00 Access types jsanchor
1998-05-28  0:00 ` Jerry van Dijk
1998-05-29  0:00   ` jsanchor
1998-05-30  0:00     ` Jerry van Dijk
replies disabled

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