Writing and reading to a memory mapped file in OCaml

memory-mapped-files, ocaml

Solution

I'm making this an answer (I was originally afraid that I missed your point). The OCaml library provides a mechanism for this by default, namely, the `map_file` function from the `Bigarray.Genarray` module. It does precisely what you want and amounts to `mmap`'ing the file under Unix. I'm unsure about the Windows specifics.

This has the advantage of being well-supported and well-tested, as well as not requiring you to import JaneSt's Core into your project if you didn't need it already.

Problem

I am experimenting in OCaml to see how I can read/write a numerical array to/from a memory mapped file. I think I'll need to use Bigarray but not sure how to write down a Bigarray array to a memory mapped file, and then read it back? I cannot seem to find an example anywhere. I have checked the source code of Jane St. core but to no avail.

Original source