comp.lang.ada
 help / color / mirror / Atom feed
From: Mark Lorenzen <mark.lorenzen@ofir.dk>
Subject: Re: Converting access values
Date: 06 Jan 2005 01:28:42 +0100
Date: 2005-01-06T01:28:42+01:00	[thread overview]
Message-ID: <m31xczwgcl.fsf@0x535ba1f6.boanxx18.adsl-dhcp.tele.dk> (raw)
In-Reply-To: bt%Cd.1342$Pm6.1117@newsread1.news.pas.earthlink.net

Jeffrey Carter <spam@spam.com> writes:

> 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.

My problem is not passing a slice as an actual parameter to a
subprogram. I have a task which receives Buf, slices it up and then
passes the slices to other tasks using queues implemented as protected
types. When passing the slice to a queue, it will probably not be done
by copy, but the queue puts the slice into a data structure (list,
array etc.) and there we definately have a real assignment and copy.
 
> 
> -- 
> Jeff Carter
> "It's all right, Taggart. Just a man and a horse being hung out there."
> Blazing Saddles
> 34

- Mark Lorenzen



  reply	other threads:[~2005-01-06  0:28 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 [this message]
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
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