Re: Converting access values
From: Mark Lorenzen (mark.lorenzen_at_ofir.dk)
Date: 01/06/05
- Next message: Randy Brukardt: "Re: Writing changelog entries"
- Previous message: Ludovic Brenta: "Re: A bug in gnat/gcc 3.3.3?"
- In reply to: Duncan Sands: "Re: Converting access values"
- Next in thread: Randy Brukardt: "Re: Converting access values"
- Reply: Randy Brukardt: "Re: Converting access values"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 06 Jan 2005 20:30:27 +0100
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
- Next message: Randy Brukardt: "Re: Writing changelog entries"
- Previous message: Ludovic Brenta: "Re: A bug in gnat/gcc 3.3.3?"
- In reply to: Duncan Sands: "Re: Converting access values"
- Next in thread: Randy Brukardt: "Re: Converting access values"
- Reply: Randy Brukardt: "Re: Converting access values"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|