comp.lang.ada
 help / color / mirror / Atom feed
* How To Create And Use Memory Map Files
@ 2019-02-16 19:40 Michael390@gmail.com
  2019-02-16 19:58 ` Simon Wright
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Michael390@gmail.com @ 2019-02-16 19:40 UTC (permalink / raw)


How does Ada do memory map files? Can you give me a few small, but easy to read, programs showing the various aspects of using memory map files in Ada?

I'd like to know the intricacies of using memory map files.

What is the documentation and what else should I know?

Thank you,
Mike 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How To Create And Use Memory Map Files
  2019-02-16 19:40 How To Create And Use Memory Map Files Michael390@gmail.com
@ 2019-02-16 19:58 ` Simon Wright
  2019-02-16 21:13 ` Per Sandberg
  2019-02-17 22:41 ` Rego, P.
  2 siblings, 0 replies; 10+ messages in thread
From: Simon Wright @ 2019-02-16 19:58 UTC (permalink / raw)


"Michael390@gmail.com" <ashos.owner@gmail.com> writes:

> How does Ada do memory map files? Can you give me a few small, but
> easy to read, programs showing the various aspects of using memory map
> files in Ada?
>
> I'd like to know the intricacies of using memory map files.
>
> What is the documentation and what else should I know?


I'm not sure what you mean by 'memory map files'.

Do you mean the map that the linker can output, showing where objects in
the link appear in store?

Or perhaps you mean a way of making a file appear as an array of bytes,
so it looks as though it's in memory? (mmap(2)) - in which case, GNAT
provides System.Mmap - look for s-mmap.ads.

Darwin users are be SOL with this (System.Mmap.OS_Interface is missing),
but you should be OK on Linux.

The files that _are_ present recommend looking at
http://www.sqlite.org/mmap.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How To Create And Use Memory Map Files
  2019-02-16 19:40 How To Create And Use Memory Map Files Michael390@gmail.com
  2019-02-16 19:58 ` Simon Wright
@ 2019-02-16 21:13 ` Per Sandberg
  2019-02-16 21:34   ` Dmitry A. Kazakov
  2019-02-17 22:41 ` Rego, P.
  2 siblings, 1 reply; 10+ messages in thread
From: Per Sandberg @ 2019-02-16 21:13 UTC (permalink / raw)


Well
I would rephrase the question like what libraries in Ada are there out 
there that provides interfaces to memory mapped files, since as far as i 
know there ar no programming languages that know anything about memory 
mapped files only a bunch of libraries that happens to be written in a 
specific language.

And one library that provides such a service is:
	https://github.com/AdaCore/gnatcoll-core/
and there may be others.

/P



On 2/16/19 8:40 PM, Michael390@gmail.com wrote:
> How does Ada do memory map files? Can you give me a few small, but easy to read, programs showing the various aspects of using memory map files in Ada?
> 
> I'd like to know the intricacies of using memory map files.
> 
> What is the documentation and what else should I know?
> 
> Thank you,
> Mike
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How To Create And Use Memory Map Files
  2019-02-16 21:13 ` Per Sandberg
@ 2019-02-16 21:34   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 10+ messages in thread
From: Dmitry A. Kazakov @ 2019-02-16 21:34 UTC (permalink / raw)


On 2019-02-16 22:13, Per Sandberg wrote:

> I would rephrase the question like what libraries in Ada are there out 
> there that provides interfaces to memory mapped files, since as far as i 
> know there ar no programming languages that know anything about memory 
> mapped files only a bunch of libraries that happens to be written in a 
> specific language.

It depends on the concrete aspect of memory mapping you are interested 
in. In fact, all of interprocess-communication in Simple Components is 
based on memory-mapped files:

 
http://www.dmitry-kazakov.de/ada/components.htm#inter-process_communucation

Both in Linux/FreeBSD and Windows memory-sharing is based on 
memory-mapped files. Under Linux even synchronization objects (e.g. 
futex) must be memory-mapped file resident. So it goes.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How To Create And Use Memory Map Files
  2019-02-16 19:40 How To Create And Use Memory Map Files Michael390@gmail.com
  2019-02-16 19:58 ` Simon Wright
  2019-02-16 21:13 ` Per Sandberg
@ 2019-02-17 22:41 ` Rego, P.
  2019-02-18  8:19   ` Dmitry A. Kazakov
  2 siblings, 1 reply; 10+ messages in thread
From: Rego, P. @ 2019-02-17 22:41 UTC (permalink / raw)


> How does Ada do memory map files? Can you give me a few small, but easy to read, programs showing the various aspects of using memory map files in Ada?

If I understood you well, you are referring to those Linux memory areas mapped into files under the OS. If so, you can treat them as usual files, eg

   with Text_IO;
   with Ada.Exceptions;
   ...
   declare
      Full_Name : constant String := "/etc/somefile";
      Curr_File : Text_IO.File_Type;
      Cmd : constant String := "5";
   begin
      Text_IO.Open (Curr_File, Text_IO.Out_File, Full_Name);
      Text_IO.Put_Line (Curr_File, Cmd);
      Text_IO.Close (Curr_File);
   exception
      when The_Error : others =>
         Text_IO.Put_Line("!!! "&Ada.Exceptions.Exception_Information (The_Error));
   end;


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How To Create And Use Memory Map Files
  2019-02-17 22:41 ` Rego, P.
@ 2019-02-18  8:19   ` Dmitry A. Kazakov
  2019-02-18  9:31     ` Rego, P.
  2019-02-18 10:44     ` Niklas Holsti
  0 siblings, 2 replies; 10+ messages in thread
From: Dmitry A. Kazakov @ 2019-02-18  8:19 UTC (permalink / raw)


On 2019-02-17 23:41, Rego, P. wrote:
>> How does Ada do memory map files? Can you give me a few small, but easy to read, programs showing the various aspects of using memory map files in Ada?
> 
> If I understood you well, you are referring to those Linux memory areas mapped into files under the OS. If so, you can treat them as usual files, eg

Usually it is the reverse: to treat a file as an chunk of memory.

In more OSes more advanced than Linux one can have shared memory without 
any files involved. The memory object could even be anonymous if one 
process passes a handle to the memory to another.

Linux has special sockets for passing file descriptors, but all is quite 
purposeless because shared memory still requires a file behind it.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How To Create And Use Memory Map Files
  2019-02-18  8:19   ` Dmitry A. Kazakov
@ 2019-02-18  9:31     ` Rego, P.
  2019-02-18 10:23       ` Dmitry A. Kazakov
  2019-02-18 10:44     ` Niklas Holsti
  1 sibling, 1 reply; 10+ messages in thread
From: Rego, P. @ 2019-02-18  9:31 UTC (permalink / raw)


> Usually it is the reverse: to treat a file as an chunk of memory.
> 
> In more OSes more advanced than Linux one can have shared memory without 
> any files involved. The memory object could even be anonymous if one 
> process passes a handle to the memory to another.
> 
> Linux has special sockets for passing file descriptors, but all is quite 
> purposeless because shared memory still requires a file behind it.

Good to know. I remember VxWorks had some mechanism like this, but I didn't 
go deep.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How To Create And Use Memory Map Files
  2019-02-18  9:31     ` Rego, P.
@ 2019-02-18 10:23       ` Dmitry A. Kazakov
  0 siblings, 0 replies; 10+ messages in thread
From: Dmitry A. Kazakov @ 2019-02-18 10:23 UTC (permalink / raw)


On 2019-02-18 10:31, Rego, P. wrote:
>> Usually it is the reverse: to treat a file as an chunk of memory.
>>
>> In more OSes more advanced than Linux one can have shared memory without
>> any files involved. The memory object could even be anonymous if one
>> process passes a handle to the memory to another.
>>
>> Linux has special sockets for passing file descriptors, but all is quite
>> purposeless because shared memory still requires a file behind it.
> 
> Good to know. I remember VxWorks had some mechanism like this, but I didn't
> go deep.

Right, VxWorks has it better, IMO.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How To Create And Use Memory Map Files
  2019-02-18  8:19   ` Dmitry A. Kazakov
  2019-02-18  9:31     ` Rego, P.
@ 2019-02-18 10:44     ` Niklas Holsti
  2019-02-19  9:26       ` Patrick Jakubowski
  1 sibling, 1 reply; 10+ messages in thread
From: Niklas Holsti @ 2019-02-18 10:44 UTC (permalink / raw)


On 19-02-18 10:19 , Dmitry A. Kazakov wrote:

> In more OSes more advanced than Linux one can have shared memory without
> any files involved. The memory object could even be anonymous if one
> process passes a handle to the memory to another.

Linux supports the "Unix System V" inter-process communication 
mechanisms, including shared memory segments that are not memory-mapped 
files and can be anonymous in the above sense.

See e.g. http://man7.org/linux/man-pages/man7/svipc.7.html

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How To Create And Use Memory Map Files
  2019-02-18 10:44     ` Niklas Holsti
@ 2019-02-19  9:26       ` Patrick Jakubowski
  0 siblings, 0 replies; 10+ messages in thread
From: Patrick Jakubowski @ 2019-02-19  9:26 UTC (permalink / raw)


On Monday, 18 February 2019 11:44:33 UTC+1, Niklas Holsti  wrote:
> On 19-02-18 10:19 , Dmitry A. Kazakov wrote:
> 
> > In more OSes more advanced than Linux one can have shared memory without
> > any files involved. The memory object could even be anonymous if one
> > process passes a handle to the memory to another.
> 
> Linux supports the "Unix System V" inter-process communication 
> mechanisms, including shared memory segments that are not memory-mapped 
> files and can be anonymous in the above sense.
> 
> See e.g. http://man7.org/linux/man-pages/man7/svipc.7.html

In Linux even memory mapped files are not necessary backed by a file. It can be just pages of memory even without file descriptor. These mappings are called ANONYMOUS and can be both private to a process or shared between processes. I did quick look at gnatcoll and that library doesn't support anonymous mappings.I would make quick C function call to mmap() or modify GNATCOLL.Mmap package.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-02-19  9:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-16 19:40 How To Create And Use Memory Map Files Michael390@gmail.com
2019-02-16 19:58 ` Simon Wright
2019-02-16 21:13 ` Per Sandberg
2019-02-16 21:34   ` Dmitry A. Kazakov
2019-02-17 22:41 ` Rego, P.
2019-02-18  8:19   ` Dmitry A. Kazakov
2019-02-18  9:31     ` Rego, P.
2019-02-18 10:23       ` Dmitry A. Kazakov
2019-02-18 10:44     ` Niklas Holsti
2019-02-19  9:26       ` Patrick Jakubowski

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