From: jsa@alexandria (Jon S Anthony)
Subject: Re: [Q]: arrays into mmap'ed memory
Date: 1996/08/29
Date: 1996-08-29T00:00:00+00:00 [thread overview]
Message-ID: <JSA.96Aug28211608@alexandria> (raw)
In-Reply-To: 32249A94.4A0A@joy.ericsson.se
In article <32249A94.4A0A@joy.ericsson.se> Jonas Nygren <jonas@joy.ericsson.se> writes:
> Can anybody help me with how to use mmap'ed memory in Ada. What I want
> to do is mmap a large file and then access parts of the so mapped
> memory via arrays.
One obvious hack:
-- Don't create an instance of this or you'll blow out with storage
-- error or something. It's just to get a template...
--
type my_mmarray_type is array (0..natural'last) of whatever;
-- Probably should really use Interfaces.C.Pointer stuff, but this
-- gives the idea...
--
type my_mmarray_ref is access all my_mmarray_type;
the_file : my_mmarray_ref := address from mmap
You use the len from mmap to get the bounds just like for C. In your
case, _whatever_ would most likely be Character. A somewhat nicer
approach would be:
type my_mmarray_type is array (natural range <>) of character;
-- Prior to entering the following declarative region call the mmap
-- function getting the address and len stuff.
subtype mm_index_type is natural range 0..len;
-- Create _constrained_ subtype.
--
subtype actual_mmarray_type is my_mmarray_type(mm_index_type);
type actual_mmarray_ref is access all actual_mmarray_type;
the_file : actual_mmarray_ref := pa;
...
begin
...
-- Now you can proceed to write bounds independent stuff:
--
for I in mm_index_type'range loop
text_io.put(the_file(i));
end loop;
-- etc.
/Jon
--
Jon Anthony
Organon Motives, Inc.
1 Williston Road, Suite 4
Belmont, MA 02178
617.484.3383
jsa@organon.com
next prev parent reply other threads:[~1996-08-29 0:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-08-28 0:00 [Q]: arrays into mmap'ed memory Jonas Nygren
1996-08-28 0:00 ` David C. Hoos, Sr.
1996-08-29 0:00 ` Jon S Anthony [this message]
1996-08-30 0:00 ` [Q]: " Norman H. Cohen
1996-08-31 0:00 ` Geert Bosch
1996-08-31 0:00 ` Laurent Guerby
1996-09-06 0:00 ` Norman H. Cohen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox