comp.lang.ada
 help / color / mirror / Atom feed
From: "David Botton" <David@Botton.com>
Subject: Re: A copy question....
Date: Tue, 16 Oct 2001 19:00:47 -0400
Date: 2001-10-16T19:00:47-04:00	[thread overview]
Message-ID: <tspf10m2tu50ca@corp.supernews.com> (raw)
In-Reply-To: 9qedad$i1p$1@newstoo.ericsson.se

----- Original Message -----
From: "Zebylon" <sebastian.madunic@esavionics.se>
> Is there some smart way of placing the data in the array...?

This is my favorite method and if you don't need a copy, but just an easy
way to access the memory, you can just use the returned Pointer_To_The_Array
directly instead of copying it.

I think the compiler will likely figure out the best way to make the block
copy on the platform :-)


with GNAT.IO; use GNAT.IO;

with Ada.Unchecked_Conversion;

with System;
with Interfaces;

procedure Block is

   type My_Array is array (Integer range <>) of Interfaces.Unsigned_32;

   Stuff_In_Memory : My_Array (1 .. 200) := (others => 999);

   Address     : System.Address := Stuff_In_Memory (1)'Address;
   Data_Length : Natural := Stuff_In_Memory'Length;

   type The_Array is new My_Array (1 .. Data_Length);
   type Pointer_To_The_Array is access all The_Array;

   function To_Pointer_To_The_Array is
      new Ada.Unchecked_Conversion (System.Address, Pointer_To_The_Array);

   Copied_Array : The_Array := To_Pointer_To_The_Array (Address).all;
begin
   for N in Copied_Array'Range loop
      Put_Line (Copied_Array (N)'Img);
   end loop;
end Block;





      parent reply	other threads:[~2001-10-16 23:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-15 10:40 A copy question Zebylon
2001-10-15 11:21 ` Dale Stanbrough
2001-10-15 11:30   ` Dale Stanbrough
2001-10-15 11:59     ` Petter Fryklund
2001-10-15 21:04       ` Dale Stanbrough
2001-10-16  2:34         ` Jeffrey Carter
2001-10-16 11:15           ` Dale Stanbrough
2001-10-15 13:38   ` Ted Dennison
2001-10-15 13:30 ` Mark Doherty
2001-10-15 17:00 ` tmoran
2001-10-16 10:09   ` Mark Doherty
2001-10-17  0:18     ` tmoran
2001-10-17  1:14       ` David Botton
2001-10-16 23:00 ` David Botton [this message]
replies disabled

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