Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Matching when
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Lex Stein <stein@e...>
Subject: Re: [Caml-list] Sharing Files between OCaml and C

On POSIX compliant systems, Dup() does not, in fact, create a new vnode
for a file. It merely creates a new file descriptor table entry (in the
process's in-kernel descriptor table) that points to exactly the same
vnode. The two descriptors share the same buffered blocks in the global
buffer cache.

So if the C and Caml sides are sharing the same vnode, through dup'ed
descriptors, it should be sufficient to flush once on either the Caml
or C side.

If however, the two references to the file are independently created
using open, then the two descriptor table entries will point to
*distinct* vnodes with independent buffering and duplicate flushing
will be necessary (although one would have to be very careful not
to overwrite changes made to the same block by the other side-- a
motivator for using dup rather than open).

Lex

On Tue, 6 Aug 2002 Bruno.Verlyck@inria.fr wrote:

>    Yes, I think that's still the best method:
>    - get the descriptor with Unix.descr_of_in_channel or
>      Unix.descr_of_out_channel
>    - fdopen it on the C side
>    You might also want to call dup() on the fd so that your FILE* stream is still
>    working if the original caml channel is closed.
> But of course you now have two concurrent buffering mechanisms, so flushing when
> switching the writing side (C vs Caml) for out_channels is mandatory, and
> seeking cautiously when switching the reading side (for in_channels) too.
>
> Bruno.
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners