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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC 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: ncohen@watson.ibm.com (Norman H. Cohen) Subject: Re: [Q]: arrays into mmap'ed memory Date: 1996/08/30 Message-ID: <507dq7$ftm@watnews1.watson.ibm.com>#1/1 X-Deja-AN: 177492523 distribution: world references: <32249A94.4A0A@joy.ericsson.se> organization: IBM T.J. Watson Research Center reply-to: ncohen@watson.ibm.com newsgroups: comp.lang.ada Date: 1996-08-30T00: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. A call on mmap returns an address, so the more general question you are asking is how to view the storage at a given address as an Ada array. One approach is to declare an array of the appropriate size and then use an address clause to specify the array's address. In Ada 95, another approach is to declare a constrained array type, declare an access type pointing to values of that array type, and use an instance of System.Address_To_Access_Conversions to convert the address to an access value A. This access value can be passed around the program, and the I\th component of the array can be named as A(I). |> In C it is simple since arrays are more or less a language syntax |> on top of pointers, p[i] == *(p+i). How can I connect an Ada array |> to memory allocated via mmap? I do not want to store the bounds |> of the array in the mapped file - the file should just be plain |> ASCII. As long as you stick to constrained array types, a typical Ada implementation will not try to store the bounds of the array in or adjacent to the addressed storage (or expect to find them stored there). |> If I manage to get the array to point to the memory and |> the bounds to be set correctly what will happen when Ada tries to |> reclaim the array? Since Ada did not allocate the array (either during the elaboration of an object declaration or the evaluation of an allocator) Ada will not try to deallocate it. -- Norman H. Cohen ncohen@watson.ibm.com