comp.lang.ada
 help / color / mirror / Atom feed
* RE: Help with Copying Shared Memory to Local
@ 2002-05-24 14:22 Beard, Frank [Contractor]
  2002-05-24 19:30 ` Jeffrey Carter
  0 siblings, 1 reply; 18+ messages in thread
From: Beard, Frank [Contractor] @ 2002-05-24 14:22 UTC (permalink / raw)


Jeffrey Carter wrote:

> 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);
>

Jeff,

Just curious.  Why the "pragma Import" on the object?

On our last Unix (HP-UX BLS) project, I wrote a generic package
that worked very similar to your suggestion.  The generic had
methods that wrappered all the appropriate OS calls for managing
the shared memory.

When the package was instantiated with the desired type, it gave
you an object of that type who's address would be mapped to shared
memory with a call to the Get_Shared_Memory method in the generic.
Once that was done, you just accessed the object just like any other, 
making it transparent to the user that it was in shared memory.

My point to this is I did a "pragma Import" on the OS calls, such as 
ShmGet (what a descriptive name), but I didn't have to do a "pragma 
Import" on the object.  What does it buy you to do the import on the
object?

Thanks
Frank



^ permalink raw reply	[flat|nested] 18+ messages in thread
* Help with Copying Shared Memory to Local
@ 2002-05-23 13:50 John Cupak
  2002-05-23 20:32 ` Jeffrey Carter
  0 siblings, 1 reply; 18+ messages in thread
From: John Cupak @ 2002-05-23 13:50 UTC (permalink / raw)


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
   
  Destination_Pointer : Project_Types.Double_Byte_Pointer;
  Source_Pointer      : Project_Types.Double_Byte_Pointer;
   
begin -- Copy_Double_Byte
   
  -- Ensure source address in correct range
  if Source >= System.Addresses.Logical_Address(Project_Types.Virtual_Base_Address)
and
  Source < System.Addresses.Logical_Address(Project_Types.Virtual_Base_Address
+ 16#200_000#) then
      
     -- Must reference memory on double byte boundry
     -- The number of bytes to copy is specified by the Length
parameter
     for Index in 0..(Length/2) - 1 loop
         
        -- Create source and destination pointers from base address
plus double byte offsets
        Destination_Pointer := Project_Types.To_Double_Byte_Pointer(
                                
System.Deprecated.Incr_Addr(Destination, Index * 2));
        Source_Pointer      := Project_Types.To_Double_Byte_Pointer(
                                 System.Deprecated.Incr_Addr(Source,  
   Index * 2));
         
        -- Copy contents
        Destination_Pointer.all := Source_Pointer.all;
         
     end loop;
      
  end if; -- Source check
   
end Copy_Double_Byte;

I found a 1997 reference in this newsgroup (comp.lang.ada) to a
similar problem entitled
"Q: How to do memory access with gnat" from Michael Erdman
(boavista@berlin.snafu.de)
with references to the Ada95 System.Address_To_Access_Conversions
child package and
the System.Storage_Elements child package.

So, before I go off and write up a new version of the "memory copy"
procedure using
these two child packages, has anyone ever implemented such a solution
that would be
willing to share?

Comments and recommendations always appreciated.

John Cupak



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2002-05-28 17:52 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-24 14:22 Help with Copying Shared Memory to Local Beard, Frank [Contractor]
2002-05-24 19:30 ` Jeffrey Carter
  -- strict thread matches above, loose matches on Subject: below --
2002-05-23 13:50 John Cupak
2002-05-23 20:32 ` Jeffrey Carter
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

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