comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <nick.roberts@acm.org>
Subject: Re: Type conversions on pool-specific access types
Date: Thu, 16 Oct 2003 02:43:08 +0100
Date: 2003-10-16T02:43:08+01:00	[thread overview]
Message-ID: <bmkt3b$nfhgh$1@ID-25716.news.uni-berlin.de> (raw)
In-Reply-To: 7kukov45dif9p7u2ohu6ml29mu9cgu621o@4ax.com

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:7kukov45dif9p7u2ohu6ml29mu9cgu621o@4ax.com...

> Who knows any reason why conversions between pool-
> specific access types are not allowed, provided that
> the storage pools are same? Isn't storage pool static-
> ally known?
>
> It is a real pain to use Unchecked_Conversion ...

I think it's also dangerous and unnecessary.

> type Base is new Ada.Limited_Controlled with ..;
> type Base_Ptr is access Base'Class;
> for Base_Ptr'Storage_Pool use ...;
>
> procedure Foo (Object : Base_Ptr);
> ...
> type Derived is new Base with ..;
> type Derived_Ptr is access Derived'Class;
> for Derived_Ptr'Storage_Pool use Base_Ptr'Storage_Pool;
> ...
> declare
>    Ptr : Derived_Ptr := new Derived;
> begin
>    Foo (Base_Ptr (Ptr)); -- ILLEGAL!
>
> I do not understand why.

In this situation, I suggest that you do not need to declare Derived_Ptr,
since Base_Ptr can -- and generally should -- be used to point to objects of
type Derived (as well as Base).

   declare
      Ptr : Base_Ptr := new Derived;
   begin
      Foo(Ptr);

> Another thing is initialization / finalization of controlled
> objects allocated on some specific storage pool. It could
> be a great problem if a pool-specific pointer is required ...

The answer is "Don't do that!"

Finalize should finalise whatever is inside the given Object, and not deal
in any way with where (in which pool) the object resides. After the
implementation has called Finalize for the object, it will then -- when
appropriate -- call Deallocate for the object's pool, in order to deallocate
the object's storage space from the pool. Do not mess with this mechanism.

--
Nick Roberts





  reply	other threads:[~2003-10-16  1:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-13 10:34 Type conversions on pool-specific access types Dmitry A. Kazakov
2003-10-16  1:43 ` Nick Roberts [this message]
2003-10-16 12:13   ` Dmitry A. Kazakov
2003-10-16 20:28     ` Nick Roberts
2003-10-17  4:27       ` Nick Roberts
2003-10-18  9:59       ` Dmitry A. Kazakov
replies disabled

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