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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4947e94bd021c540 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-07 19:14:49 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!wn14feed!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc51.ops.asp.att.net.POSTED!not-for-mail Message-ID: <3F837303.9040202@comcast.net> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: C array to Ada pointer to unconstrained array without copying memory References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.34.139.183 X-Complaints-To: abuse@comcast.net X-Trace: rwcrnsc51.ops.asp.att.net 1065579289 24.34.139.183 (Wed, 08 Oct 2003 02:14:49 GMT) NNTP-Posting-Date: Wed, 08 Oct 2003 02:14:49 GMT Organization: Comcast Online Date: Wed, 08 Oct 2003 02:14:49 GMT Xref: archiver1.google.com comp.lang.ada:428 Date: 2003-10-08T02:14:49+00:00 List-Id: Duncan Sands wrote: > So far so good. Now suppose I do: > > Y : Array_Pointer := new Array_Type' (X); -- (*) > > The object I want is Y. What is the problem? The problem > is that line (*) involves allocating memory and copying the > data from X to that memory. I would like to end up with Y > without performing the copy (and without reallocating > memory for the array data). What is wrong with: Y: Array_Type; for Y'Address use X'Address; ..if you want X and Y to be two different views of the same memory. Notice that there is no need for an explicit pointer here, but if X is a pointer as in your example, you may want to do: Y: Array_Type; for Y'Address use X.all'Address; Oh, and if there is initialization for the elements of Array_Type you may want to add a pragma Import; to turn off initialization. -- Robert I. Eachus "Quality is the Buddha. Quality is scientific reality. Quality is the goal of Art. It remains to work these concepts into a practical, down-to-earth context, and for this there is nothing more practical or down-to-earth than what I have been talking about all along...the repair of an old motorcycle." -- from Zen and the Art of Motorcycle Maintenance by Robert Pirsig