comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: Help with Copying Shared Memory to Local
Date: Thu, 23 May 2002 20:32:30 GMT
Date: 2002-05-23T20:32:30+00:00	[thread overview]
Message-ID: <3CED51CF.39E26FC6@acm.org> (raw)
In-Reply-To: c7990eda.0205230550.203d300a@posting.google.com

John Cupak wrote:
> 
> A colleague asked me to help him solve an memory copy problem.
> 
> The source memory location is in a "shared" area, and the
> destination memory location is "local" to the application.
> 
> The original code, written in Ada83, works by copying two bytes
> at a time. Evidently, the hardware crashes if they try to access
> a single byte.
> 
> Here's the Ada 95 version of the original Ada83 code:
> 
> -- Assumed visibility of Project_Types
> procedure Copy_Double_Byte(Destination : in System.Address;
>                            Source      : in System.Address;
>                            Length      : in Natural) is

There's about a 9 out of 10 chance that this system does not need to be
dealing with addresses; that this way of doing things was dreamed up by
a C person who lacked the necessary familiarity with Ada 83 to be
competent to create this specification. I have seen this kind of misuse
of the language far too many times for it to be likely that this case is
different.

You rarely need to use addresses in Ada; this particular example almost
certainly did not need to use addresses even in Ada 83. Maybe you're
stuck with it, in which case you can probably do

Storage_Length : constant Storage_Count :=
   Storage_Count ( (8 * Length + Storage_Unit - 1) / Storage_Unit);
-- Convert Length (in 8-bit bytes) to work with Storage_Elements

A : Storage_Array (1 .. Storage_Length);
for A'Address use Destination;
pragma Import (Ada, A);

B : Storage_Array (1 .. Storage_Length);
for B'Address use Source;
pragma Import (Ada, B);

...

A := B;

-- 
Jeff Carter
"We call your door-opening request a silly thing."
Monty Python & the Holy Grail



  reply	other threads:[~2002-05-23 20:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-23 13:50 Help with Copying Shared Memory to Local John Cupak
2002-05-23 20:32 ` Jeffrey Carter [this message]
2002-05-23 21:18   ` John Cupak
2002-05-24  1:37     ` Randy Brukardt
2002-05-24  2:08       ` Jeffrey Carter
2002-05-24 17:05         ` John R. Strohm
2002-05-24 16:55           ` Stephen Leake
2002-05-24 20:43             ` John R. Strohm
2002-05-24 19:49               ` Pat Rogers
2002-05-24 23:23                 ` martin.m.dowie
2002-05-24 20:54               ` Stephen Leake
2002-05-24 19:41           ` Jeffrey Carter
2002-05-26  0:55           ` John Cupak
2002-05-28 17:52             ` John Cupak
2002-05-25 11:23   ` Robert Dewar
2002-05-26  4:48     ` Jeffrey Carter
  -- strict thread matches above, loose matches on Subject: below --
2002-05-24 14:22 Beard, Frank [Contractor]
2002-05-24 19:30 ` Jeffrey Carter
replies disabled

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