comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Address of an object
Date: Fri, 15 Sep 2006 22:24:39 +0200
Date: 2006-09-15T22:24:24+02:00	[thread overview]
Message-ID: <382nx7mt637x$.6hjqgb4zxzss.dlg@40tude.net> (raw)

Both X'Address and Unchecked_Conversion of a pointer to X would not give
the true address of X (i.e. the address returned by Allocate of the
corresponding storage pool). For an array type, X'Address is the address of
the first element, the dope is out.

Is there any better way than this extremely ugly and slow:

   type Fake_Pool is new Root_Storage_Pool with record
      Location : Address;
   end record;

   procedure Allocate (...) is -- Never called
   begin
      raise Program_Error;
   end Allocate;

   procedure Deallocate
             (  Pool            : in out Fake_Pool; 
                Storage_Address : in Address; 
                Size            : Storage_Count;
                Alignment       : Storage_Count
             )  is
   begin
      Pool.Location := Storage_Address;
   end Deallocate;

   function Storage_Size (Pool : Fake_Pool) -- Never called
      return Storage_Count is
   begin
      return 0;
   end Storage_Size;

   function Address_Of (Pointer : Object_Ptr) return Address is
      Pool : Fake_Pool; -- A controlled object, that must be slow!
      type Fake_Ptr is access Object_Type;
      for Fake_Ptr'Storage_Pool use Pool;
      function To_Fake is
         new Ada.Unchecked_Conversion (Object_Ptr, Fake_Ptr);
      procedure Free is
         new Ada.Unchecked_Deallocation (Object_Type, Fake_Ptr);
      Ptr : Fake_Ptr := To_Fake (Pointer);
   begin
      Free (Ptr);
      return Pool.Location;
   end Address_Of;

?

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



             reply	other threads:[~2006-09-15 20:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-15 20:24 Dmitry A. Kazakov [this message]
2006-09-15 23:31 ` Address of an object Adam Beneschan
2006-09-16  8:13   ` Dmitry A. Kazakov
2006-09-18 10:29     ` Stephen Leake
2006-09-18 12:09       ` Dmitry A. Kazakov
2006-09-18 13:54         ` Maciej Sobczak
2006-09-18 14:53           ` Dmitry A. Kazakov
2006-09-19  9:15         ` Stephen Leake
2006-09-19 13:29           ` Dmitry A. Kazakov
2006-09-16 13:21 ` Stephen Leake
2006-09-16 17:06   ` Dmitry A. Kazakov
2006-09-20  0:43     ` Randy Brukardt
replies disabled

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