From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a9026b81108642ee X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Address of an object Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <382nx7mt637x$.6hjqgb4zxzss.dlg@40tude.net> <1158363114.393740.59040@h48g2000cwc.googlegroups.com> Date: Sat, 16 Sep 2006 10:13:46 +0200 Message-ID: <1i3ne95psolai.abl9eureg5t9$.dlg@40tude.net> NNTP-Posting-Date: 16 Sep 2006 10:13:29 CEST NNTP-Posting-Host: 086950fe.newsspool3.arcor-online.net X-Trace: DXC=R]o1Nn5<4cA=8m7nZkdN^@McF=Q^Z^V3H4Fo<]lROoRA4nDHegD_]RE]Z4FkTfB On 15 Sep 2006 16:31:54 -0700, Adam Beneschan wrote: > Dmitry A. Kazakov wrote: >> 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; >> >> ? > > This sounds highly implementation-dependent. At best! > I don't think there's an implementation-independent way to get what > you're looking for (and, frankly, I'm not even sure there's an > implementation-independent way to *define* what you're looking for). > Assuming that you're interested in only one implementation, perhaps you > can ask the implementors to provide an implementation-dependent > attribute or something to give you what you need. Hmm, actually it is quite easy to define formally: Let P be a pointer to X. Then what I need is the address A, which the pool P'Storage_Pool returned when X was allocated there. This is the same address the pool will receive upon freeing X. ---------- The problem behind. What I need is to be able to add some dopes to the objects allocated in *my* pool. new T calls to the pool's Allocate, but the address it returns gets mangled by the compiler, when converted to the pointer P [for example, when T is String]. So, having P I cannot get at my dope. Its address should be A = P.all'Address - Offs where Offs is known, alas, to the compiler only. The compiler must know that, otherwise it couldn't pass that to Deallocate. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de