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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c4003439e5ce36e1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!newspeer.monmouth.com!news.tele.dk!news.tele.dk!small.news.tele.dk!not-for-mail Sender: malo@0x53586c58.boanxx18.adsl-dhcp.tele.dk Newsgroups: comp.lang.ada Subject: Re: Converting access values References: From: Mark Lorenzen Date: 06 Jan 2005 20:30:27 +0100 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: TDC Totalloesninger NNTP-Posting-Host: 83.88.108.88 X-Trace: 1105039827 dtext02.news.tele.dk 155 83.88.108.88:28791 X-Complaints-To: abuse@post.tele.dk Xref: g2news1.google.com comp.lang.ada:7527 Date: 2005-01-06T20:30:27+01:00 List-Id: Duncan Sands 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