comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: [Q]: arrays into mmap'ed memory
Date: 1996/08/30
Date: 1996-08-30T00:00:00+00:00	[thread overview]
Message-ID: <507dq7$ftm@watnews1.watson.ibm.com> (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.

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




  parent reply	other threads:[~1996-08-30  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 ` [Q]: " Jon S Anthony
1996-08-30  0:00 ` Norman H. Cohen [this message]
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