From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8f62275ace1d51c1 X-Google-Attributes: gid103376,public From: jsa@alexandria (Jon S Anthony) Subject: Re: [Q]: arrays into mmap'ed memory Date: 1996/08/29 Message-ID: #1/1 X-Deja-AN: 177186787 sender: news@organon.com (news) references: <32249A94.4A0A@joy.ericsson.se> organization: Organon Motives, Inc. newsgroups: comp.lang.ada Date: 1996-08-29T00:00:00+00:00 List-Id: In article <32249A94.4A0A@joy.ericsson.se> Jonas Nygren 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