comp.lang.ada
 help / color / mirror / Atom feed
From: Mark Lorenzen <mark.lorenzen@ofir.dk>
Subject: Re: Converting access values
Date: 06 Jan 2005 20:30:27 +0100
Date: 2005-01-06T20:30:27+01:00	[thread overview]
Message-ID: <m3oeg28iek.fsf@0x53586c58.boanxx18.adsl-dhcp.tele.dk> (raw)
In-Reply-To: mailman.36.1105009412.527.comp.lang.ada@ada-france.org

Duncan Sands <baldrick@free.fr> writes:

> Hi Mark,
> 
> > We now want to copy parts ("slices") of the data to other tasks that
> > may do something interesting with these slices. The rate of data is
> > too high to simply copy the wanted slices, so instead we make "cheap
> > copies".
> 
> if I understand right, you have a bunch of bytes that you would like the
> rest of your program to see as an array of an unconstrained array type.

Correct.

> The problem here is: where do you put the info about the array bounds?

Also correct. I have an access type *without* dope, but need an access
type *without* dope.

> I had a similar problem where my bunch of bytes was passed to me from
> a C library, and I didn't want to make a copy of it (too big), but wanted
> to treat it as an unconstrained array.  This email I got from Steve Adams
> may interest you:
> 
> 
> 
> Re: C array to Ada pointer to unconstrained array without copying memory
> To: comp.lang.ada@ada-france.org
>  
> Duncan,
>   I have had to do this for my project. What I do is not portable really but
> in general is OK if no other solution is available.
> 
> Gnat does indeed use Fat pointers. *By Default*
> You can make it use thin pointers though:
> 
> type var_arr is array (positive range <>) of T;
> type var_arr_ptr is access var_arr;
> for var_arr_ptr'size use DWORD; -- from memory, probably want a 'size of int
> or something
> 
> The var_arr_ptr will only be a standard platform pointer size, 32 bits for
> ease in the rest of discussion.
> The pointer in *GNAT* points to the data (satisfies LRM that arr'access
> points to data) and immediately before this are
> the bounds, two ints every case i have for 1D arrays, lower then upper ->
> 
> [l bound][u bound][data....]
> 
> You need to do some pointer manipulations in C when first allocating them to
> set the bounds, but Gnat just treats the arrays as normal.
> Gnat is good like this since it means that C pointer is handled the same as
> Ada pointer.

Unfortunately this does not work in my case. I have to "copy" a slice
from the middle of an access, and the [l bound][u bound] values would
just overwrite some of the values in the array located before the
slice.

[cut]

I think I have to go for a buffer type like this:

type Buffer_Slice is
   record
     Data  : Buffer_Ptr;
     First : Ada.Streams.Stream_element_Offset;
     Last  : Ada.Streams.Stream_element_Offset;
   end record;

Where First .. Last defines the slice constraints. It is much more the
Ada-way, but it puts more responsibility on the user of the buffer
type, since he/she could easily overwrite parts of the array which is
outside the slice. It looks like my other idea is going to be very
nasty to implement.

- Mark



  parent reply	other threads:[~2005-01-06 19:30 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-05 22:31 Converting access values Mark Lorenzen
2005-01-05 23:32 ` Stephen Leake
2005-01-05 23:51   ` Mark Lorenzen
2005-01-06  0:18 ` Jeffrey Carter
2005-01-06  0:28   ` Mark Lorenzen
2005-01-07 16:55     ` Nick Roberts
2005-01-07 19:49       ` Mark Lorenzen
2005-01-07 20:23         ` Nick Roberts
2005-01-07 21:23           ` Robert A Duff
2005-01-11 17:02             ` Upkeep
2005-01-11 21:37               ` Robert A Duff
2005-01-12  4:56                 ` Alexander E. Kopilovich
2005-01-12 10:48                 ` Dmitry A. Kazakov
2005-01-07 21:17         ` Randy Brukardt
2005-01-07 22:15           ` Robert A Duff
2005-01-06 10:52 ` Dmitry A. Kazakov
2005-01-06 11:02 ` Duncan Sands
2005-01-06 12:17   ` Martin Dowie
2005-01-06 19:30   ` Mark Lorenzen [this message]
2005-01-06 20:40     ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox