comp.lang.ada
 help / color / mirror / Atom feed
From: "Chad R. Meiners" <crmeiners@hotmail.com>
Subject: Re: C array to Ada pointer to unconstrained array withoutcopyingmemory
Date: Wed, 8 Oct 2003 12:16:34 -0400
Date: 2003-10-08T12:16:34-04:00	[thread overview]
Message-ID: <bm1dbu$2nmk$1@msunews.cl.msu.edu> (raw)
In-Reply-To: mailman.49.1065604749.25614.comp.lang.ada@ada-france.org


"Duncan Sands" <duncan.sands@math.u-psud.fr> wrote in message
news:mailman.49.1065604749.25614.comp.lang.ada@ada-france.org...
> On Wednesday 08 October 2003 00:52, Chad R. Meiners wrote:
> > "Chad R. Meiners" <crmeiners@hotmail.com> wrote in message
> > news:blvfo6$q6s$1@msunews.cl.msu.edu...
> >
> > > declare
> > >     C_Data_Ptr       :  Systems.Address := To_Address(My_C_Ptr);
> > >     C_Data_Length :  Natural   := ...;
> > >
> > >     type My_Ada_Type_Element is ...;
> > >     type My_Ada_Array is array(Natural range <>) of
My_Ada_Type_Element;
> > >
> > >     subtype My_C_Data_As_An_Ada_Array_Type is
> > > My_Ada_Array(1..C_Data_Length);
> > >     package My_Converter is new
> > > Address_To_Access_Conversions(My_C_Data_As_An_Ada_Array_Type);
> > >     C_Data_In_Ada : My_Ada_Array renames
> > > My_Converter.To_Pointer(C_Data_Ptr).all;
> > >     -- No copying of the array done, but the array dope that you want
is
> > > built from the subtype information.
> > > begin
> > > ...
> > > end;
> >
> > I should probably add that you can just get the pointer with
> >
> > My_Ada_Array_Ptr : My_Converter.Object_Pointer :=
> > My_Converter.To_Pointer(C_Data_Ptr);
> >
> > I believe that this satisfies your needs?
>
> Not in the slightest.  Once you leave this local block, the pointer is
> unusable because the array dope, stored as a local variable of the
> block, will disappear.  The data continues to hang around of course.

So do the declare at the library level.

-CRM.





  reply	other threads:[~2003-10-08 16:16 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
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           ` Chad R. Meiners [this message]
2003-10-08 16:49             ` C array to Ada pointer to unconstrained array withoutcopyingmemory 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