Version française
Home     About     Download     Resources     Contact us    
Browse thread
mmap() and strings
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Basile STARYNKEVITCH <basile@s...>
Subject: Re: [Caml-list] mmap() and strings
Le Wed, Dec 08, 2004 at 09:04:59PM +0100, Julien Cristau écrivait/wrote:
> Hello list,
> 
> I'm wondering if somebody has an idea for the following problem:
> 
> I'm working on a program which manipulates a buffer. A writer process 
> regularly changes this buffer, and reader processes have to work on it 
> after each change. Currently, the buffer is a string and is passed to 
> the readers trough pipes. However, this is costly because the buffer is 
> copied many times at each iteration.

Actually, pipes perform quite well on Linux....

> We thought we could use mmap(2), 
> but there seems to be no easy solution 
> to mmap() a memory region and treat it as a string in ocaml. 

Use Bigarray-s for that. They can mmap files (on Unix & Linux) and are
already in Ocaml 3.08

You might also use IPC shared memory segments, but there is no support
in Ocaml for these (shmget & related system calls), so you'll probably
need to code the C stub (for the Ocaml binding) yourself.

Maybe you'll need JoCaml... (but I don't know if it is dead or not -
it was designed for coding cooperative programs communicating thru
channels).


-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/ 
email: basile<at>starynkevitch<dot>net 
aliases: basile<at>tunes<dot>org = bstarynk<at>nerim<dot>net
8, rue de la Faïencerie, 92340 Bourg La Reine, France