From: Duncan Sands <duncan.sands@math.u-psud.fr>
To: "Chad R. Meiners" <crmeiners@hotmail.com>, comp.lang.ada@ada-france.org
Subject: Re: C array to Ada pointer to unconstrained array without copying memory
Date: Tue, 7 Oct 2003 23:24:53 +0200
Date: 2003-10-07T23:24:53+02:00 [thread overview]
Message-ID: <mailman.41.1065561795.25614.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <blv981$jke$1@msunews.cl.msu.edu>
On Tuesday 07 October 2003 22:53, Chad R. Meiners wrote:
> "Duncan Sands" <baldrick@free.fr> 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.
next prev parent reply other threads:[~2003-10-07 21:24 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-07 14:43 C array to Ada pointer to unconstrained array without copying memory Duncan Sands
2003-10-07 18:30 ` tmoran
2003-10-07 19:24 ` Duncan Sands
2003-10-08 0:02 ` sk
[not found] ` <3F83540E.5000302@myob.com>
2003-10-08 9:18 ` Duncan Sands
2003-10-07 20:00 ` Jeffrey Carter
2003-10-07 20:39 ` Duncan Sands
2003-10-08 1:27 ` Jeffrey Carter
2003-10-07 20:53 ` Chad R. Meiners
2003-10-07 21:24 ` Duncan Sands [this message]
2003-10-07 22:44 ` C array to Ada pointer to unconstrained array without copyingmemory Chad R. Meiners
2003-10-07 22:52 ` Chad R. Meiners
2003-10-08 9:20 ` Duncan Sands
2003-10-08 16:16 ` C array to Ada pointer to unconstrained array withoutcopyingmemory Chad R. Meiners
2003-10-08 16:49 ` Duncan Sands
2003-10-08 2:14 ` C array to Ada pointer to unconstrained array without copying memory Robert I. Eachus
2003-10-08 9:27 ` Duncan Sands
2003-10-08 22:43 ` Robert I. Eachus
2003-10-09 9:31 ` Duncan Sands
2003-10-08 14:07 ` Steve Adams
2003-10-08 14:33 ` Preben Randhol
2003-10-09 23:04 ` Steve Adams
2003-10-09 23:11 ` Steve Adams
2003-10-08 16:30 ` Duncan Sands
2003-10-09 22:59 ` C array to Ada pointer to unconstrained array without copyingmemory Steve Adams
2003-10-10 7:02 ` Duncan Sands
2003-10-10 16:44 ` C array to Ada pointer to unconstrained array withoutcopyingmemory Steve Adams
2003-10-23 21:27 ` C array to Ada pointer to unconstrained array without copying memory Craig Carey
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox