diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2017-07-14 19:03:13 +0200 |
---|---|---|
committer | Gabriel Scherer <gabriel.scherer@gmail.com> | 2017-07-15 22:38:49 -0400 |
commit | eb3ced82c7b220a86769815bb7a7d8c0bfa573e6 (patch) | |
tree | 488a2fb25742c2c58d709e2504c1744c494bc136 | |
parent | 89485fe4245acf249b2c63cfc6507c1df6f8f1c1 (diff) | |
download | ocaml-map_file_omission.tar.gz |
Introduce UnixLabels.map_filemap_file_omission
This is a follow-up to the introduction of Unix.map_file in GPR#997 and GPR#1077.
-rw-r--r-- | otherlibs/unix/unixLabels.mli | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/otherlibs/unix/unixLabels.mli b/otherlibs/unix/unixLabels.mli index 058198d534..b12b3133ce 100644 --- a/otherlibs/unix/unixLabels.mli +++ b/otherlibs/unix/unixLabels.mli @@ -430,6 +430,59 @@ module LargeFile : whose sizes are greater than [max_int]. *) +(** {6 Mapping files into memory} *) + +val map_file : + file_descr -> ?pos:int64 -> kind:('a, 'b) CamlinternalBigarray.kind -> + layout:'c CamlinternalBigarray.layout -> shared:bool -> dims:int array -> + ('a, 'b, 'c) CamlinternalBigarray.genarray +(** Memory mapping of a file as a big array. + [map_file fd kind layout shared dims] + returns a big array of kind [kind], layout [layout], + and dimensions as specified in [dims]. The data contained in + this big array are the contents of the file referred to by + the file descriptor [fd] (as opened previously with + [Unix.openfile], for example). The optional [pos] parameter + is the byte offset in the file of the data being mapped; + it defaults to 0 (map from the beginning of the file). + + If [shared] is [true], all modifications performed on the array + are reflected in the file. This requires that [fd] be opened + with write permissions. If [shared] is [false], modifications + performed on the array are done in memory only, using + copy-on-write of the modified pages; the underlying file is not + affected. + + [Genarray.map_file] is much more efficient than reading + the whole file in a big array, modifying that big array, + and writing it afterwards. + + To adjust automatically the dimensions of the big array to + the actual size of the file, the major dimension (that is, + the first dimension for an array with C layout, and the last + dimension for an array with Fortran layout) can be given as + [-1]. [Genarray.map_file] then determines the major dimension + from the size of the file. The file must contain an integral + number of sub-arrays as determined by the non-major dimensions, + otherwise [Failure] is raised. + + If all dimensions of the big array are given, the file size is + matched against the size of the big array. If the file is larger + than the big array, only the initial portion of the file is + mapped to the big array. If the file is smaller than the big + array, the file is automatically grown to the size of the big array. + This requires write permissions on [fd]. + + Array accesses are bounds-checked, but the bounds are determined by + the initial call to [map_file]. Therefore, you should make sure no + other process modifies the mapped file while you're accessing it, + or a SIGBUS signal may be raised. This happens, for instance, if the + file is shrunk. + + [Invalid_argument] or [Failure] may be raised in cases where argument + validation fails. + @since 4.06.0 *) + (** {6 Operations on file names} *) |