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 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!news4.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.3) Gecko/20040910 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Converting access values References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Thu, 06 Jan 2005 00:18:15 GMT NNTP-Posting-Host: 63.186.48.197 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.pas.earthlink.net 1104970695 63.186.48.197 (Wed, 05 Jan 2005 16:18:15 PST) NNTP-Posting-Date: Wed, 05 Jan 2005 16:18:15 PST Xref: g2news1.google.com comp.lang.ada:7501 Date: 2005-01-06T00:18:15+00:00 List-Id: Mark Lorenzen wrote: > Hello, > > Imagine that we have a program that reads large amount of data from > (for example) a network connection into buffers. The data is just to > be seen as a sequence of octets. > > 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". > > The idea is that these cheap copies simply point to slices within the > large buffer and this way all copies refer to a common buffer and no > real copying is going on. The answer, as is often the case with Ada, is that you don't need to use access types to do what you want. Assuming you have a big Storage_Array and want to pass a slice of it somewhere, just pass the slice: Buf : Stream_Element_Array (Really_Big); ... procedure Do_Something (Data : in [out] Stream_Element_Array); ... Do_Something (Data => Buf (Low .. High) ); I don't know of any compiler that will pass Data by copy; if yours does, you should seriously consider changing compilers. What will be passed is a slice descriptor, which may be bigger than an access value but will still be very small. Actual access to the buffer will be by reference. -- Jeff Carter "It's all right, Taggart. Just a man and a horse being hung out there." Blazing Saddles 34