Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2002-08-06 (18:50)
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).


On Tue, 6 Aug 2002 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 Archives:
> Bug reports: FAQ:
> Beginner's list:

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: