comp.lang.ada
 help / color / mirror / Atom feed
* Address of an object
@ 2006-09-15 20:24 Dmitry A. Kazakov
  2006-09-15 23:31 ` Adam Beneschan
  2006-09-16 13:21 ` Stephen Leake
  0 siblings, 2 replies; 12+ messages in thread
From: Dmitry A. Kazakov @ 2006-09-15 20:24 UTC (permalink / 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



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2006-09-20  0:43 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-15 20:24 Address of an object Dmitry A. Kazakov
2006-09-15 23:31 ` 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

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