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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable 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 14:24:46 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.stueberl.de!teaser.fr!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Duncan Sands Newsgroups: comp.lang.ada Subject: Re: C array to Ada pointer to unconstrained array without copying memory Date: Tue, 7 Oct 2003 23:24:53 +0200 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1065561795 3588 80.67.180.195 (7 Oct 2003 21:23:15 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 7 Oct 2003 21:23:15 +0000 (UTC) To: "Chad R. Meiners" , comp.lang.ada@ada-france.org Return-Path: User-Agent: KMail/1.5.1 In-Reply-To: Content-Disposition: inline X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:402 Date: 2003-10-07T23:24:53+02:00 On Tuesday 07 October 2003 22:53, Chad R. Meiners wrote: > "Duncan Sands" wrote in message > news:mailman.37.1065537708.25614.comp.lang.ada@ada-france.org... > > > The problem is the bounds of course. For example, GNAT usually uses > > fat pointers, consisting of two normal pointers where one points to the > > data, and the other to the bounds. So the "clever stuff" will need to > > allocate some memory to hold the bounds and set up the fat pointer > > appropriately. > > > > Does anyone know a good way to do this? The solution only needs to > > work with GNAT. I appreciate that deallocating the pointer may need > > to be handled specially. > > See http://www.adapower.com/lang/accessmem.html method 1c using > Address_To_Access_Conversions. > > Page for strings, but it should work for any array type as long as you have > the representation correct. Thanks Chad, but in fact that was not the question :) The method you refer to makes it easy to get a local variable with the right bounds, but that is not enough for me! Here is an example. Suppose I get the result in a local array X with the right bounds: type Array_Type is (Positive range <>) of Something; type Array_Pointer is access Array_Type; ... get data and length from C ... X : Array_Type (1 .. length); for X'Address use data; -- or another method 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). All the best, Duncan.