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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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!postnews.google.com!h48g2000cwc.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: Address of an object Date: 15 Sep 2006 16:31:54 -0700 Organization: http://groups.google.com Message-ID: <1158363114.393740.59040@h48g2000cwc.googlegroups.com> References: <382nx7mt637x$.6hjqgb4zxzss.dlg@40tude.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1158363118 28789 127.0.0.1 (15 Sep 2006 23:31:58 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 15 Sep 2006 23:31:58 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: h48g2000cwc.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:6602 Date: 2006-09-15T16:31:54-07:00 List-Id: 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. I don't know what an Object_Ptr points to; but if it points to something that could be represented, in some implementations, as discontiguous data, then the above won't necessarily work---calling the instance of Unchecked_Deallocation could well cause the storage pool Deallocate routine to be called more than once. And then your result will be whatever was passed to the last Deallocate call, which may or may not be meaningful. 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. -- Adam