summaryrefslogtreecommitdiff
path: root/otherlibs/bigarray
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2007-02-21 15:16:53 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2007-02-21 15:16:53 +0000
commitd27adbc9c3b7a40b222165eb78c1f3a2cbcc6fea (patch)
tree8a5615d3d2cca0111971a82126a9b7fe9b3c0b1e /otherlibs/bigarray
parent251e86a3701e35bd119cf65e04fd1b7c6b19b6e8 (diff)
downloadocaml-d27adbc9c3b7a40b222165eb78c1f3a2cbcc6fea.tar.gz
Bigarray.*.map_subfile replaced by an optional argument to Bigarray.*.map_file
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@7891 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs/bigarray')
-rw-r--r--otherlibs/bigarray/bigarray.ml24
-rw-r--r--otherlibs/bigarray/bigarray.mli53
2 files changed, 23 insertions, 54 deletions
diff --git a/otherlibs/bigarray/bigarray.ml b/otherlibs/bigarray/bigarray.ml
index c1f107a8cf..91eab314ea 100644
--- a/otherlibs/bigarray/bigarray.ml
+++ b/otherlibs/bigarray/bigarray.ml
@@ -94,11 +94,11 @@ module Genarray = struct
external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit
= "caml_ba_blit"
external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill"
- external map_subfile: Unix.file_descr -> ('a, 'b) kind -> 'c layout ->
+ external map_internal: Unix.file_descr -> ('a, 'b) kind -> 'c layout ->
bool -> int array -> int64 -> ('a, 'b, 'c) t
= "caml_ba_map_file_bytecode" "caml_ba_map_file"
- let map_file fd kind layout shared dims =
- map_subfile fd kind layout shared dims 0L
+ let map_file fd ?(pos = 0L) kind layout shared dims =
+ map_internal fd kind layout shared dims pos
end
module Array1 = struct
@@ -118,10 +118,8 @@ module Array1 = struct
let ofs = if layout = c_layout then 0 else 1 in
for i = 0 to Array.length data - 1 do set ba (i + ofs) data.(i) done;
ba
- let map_file fd kind layout shared dim =
- Genarray.map_file fd kind layout shared [|dim|]
- let map_subfile fd kind layout shared dim ofs =
- Genarray.map_subfile fd kind layout shared [|dim|] ofs
+ let map_file fd ?pos kind layout shared dim =
+ Genarray.map_file fd ?pos kind layout shared [|dim|]
end
module Array2 = struct
@@ -157,10 +155,8 @@ module Array2 = struct
done
done;
ba
- let map_file fd kind layout shared dim1 dim2 =
- Genarray.map_file fd kind layout shared [|dim1;dim2|]
- let map_subfile fd kind layout shared dim1 dim2 ofs =
- Genarray.map_subfile fd kind layout shared [|dim1;dim2|] ofs
+ let map_file fd ?pos kind layout shared dim1 dim2 =
+ Genarray.map_file fd ?pos kind layout shared [|dim1;dim2|]
end
module Array3 = struct
@@ -206,10 +202,8 @@ module Array3 = struct
done
done;
ba
- let map_file fd kind layout shared dim1 dim2 dim3 =
- Genarray.map_file fd kind layout shared [|dim1;dim2;dim3|]
- let map_subfile fd kind layout shared dim1 dim2 dim3 ofs =
- Genarray.map_subfile fd kind layout shared [|dim1;dim2;dim3|] ofs
+ let map_file fd ?pos kind layout shared dim1 dim2 dim3 =
+ Genarray.map_file fd ?pos kind layout shared [|dim1;dim2;dim3|]
end
external genarray_of_array1: ('a, 'b, 'c) Array1.t -> ('a, 'b, 'c) Genarray.t
diff --git a/otherlibs/bigarray/bigarray.mli b/otherlibs/bigarray/bigarray.mli
index 907ef41ebc..74848843e8 100644
--- a/otherlibs/bigarray/bigarray.mli
+++ b/otherlibs/bigarray/bigarray.mli
@@ -381,7 +381,7 @@ module Genarray :
or a slice of [a]. *)
val map_file:
- Unix.file_descr -> ('a, 'b) kind -> 'c layout ->
+ Unix.file_descr -> ?pos:int64 -> ('a, 'b) kind -> 'c layout ->
bool -> int array -> ('a, 'b, 'c) t
(** Memory mapping of a file as a big array.
[Genarray.map_file fd kind layout shared dims]
@@ -389,12 +389,16 @@ module Genarray :
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). 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.
+ [Unix.openfile], for example). The optional [pos] parameter
+ is the byte offset in the file of the data being mapped;
+ it default 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,
@@ -416,16 +420,6 @@ module Genarray :
array, the file is automatically grown to the size of the big array.
This requires write permissions on [fd]. *)
- val map_subfile:
- Unix.file_descr -> ('a, 'b) kind -> 'c layout ->
- bool -> int array -> int64 -> ('a, 'b, 'c) t
- (** Memory mapping of a file as a big array. The file data being mapped
- starts at the given file offset, instead of the whole file
- (start offset 0) like [Genarray.map_file] does.
- In the call [Genarray.map_subfile fd kind layout shared dims ofs],
- the [ofs] parameter is the starting file offset; the other parameters
- are as in {!Bigarray.Genarray.map_file}. *)
-
end
(** {6 One-dimensional arrays} *)
@@ -491,16 +485,10 @@ module Array1 : sig
(** Build a one-dimensional big array initialized from the
given array. *)
- val map_file: Unix.file_descr -> ('a, 'b) kind -> 'c layout ->
+ val map_file: Unix.file_descr -> ?pos:int64 -> ('a, 'b) kind -> 'c layout ->
bool -> int -> ('a, 'b, 'c) t
(** Memory mapping of a file as a one-dimensional big array.
See {!Bigarray.Genarray.map_file} for more details. *)
-
- val map_subfile: Unix.file_descr -> ('a, 'b) kind -> 'c layout ->
- bool -> int -> int64 -> ('a, 'b, 'c) t
- (** Memory mapping of a file as a one-dimensional big array,
- starting at a given file offset.
- See {!Bigarray.Genarray.map_subfile} for more details. *)
end
@@ -590,17 +578,11 @@ module Array2 :
(** Build a two-dimensional big array initialized from the
given array of arrays. *)
- val map_file: Unix.file_descr -> ('a, 'b) kind -> 'c layout ->
+ val map_file: Unix.file_descr -> ?pos:int64 -> ('a, 'b) kind -> 'c layout ->
bool -> int -> int -> ('a, 'b, 'c) t
(** Memory mapping of a file as a two-dimensional big array.
See {!Bigarray.Genarray.map_file} for more details. *)
- val map_subfile: Unix.file_descr -> ('a, 'b) kind -> 'c layout ->
- bool -> int -> int -> int64 -> ('a, 'b, 'c) t
- (** Memory mapping of a file as a two-dimensional big array,
- starting at a given file offset.
- See {!Bigarray.Genarray.map_subfile} for more details. *)
-
end
(** {6 Three-dimensional arrays} *)
@@ -714,17 +696,10 @@ module Array3 :
(** Build a three-dimensional big array initialized from the
given array of arrays of arrays. *)
- val map_file: Unix.file_descr -> ('a, 'b) kind -> 'c layout ->
+ val map_file: Unix.file_descr -> ?pos:int64 -> ('a, 'b) kind -> 'c layout ->
bool -> int -> int -> int -> ('a, 'b, 'c) t
(** Memory mapping of a file as a three-dimensional big array.
See {!Bigarray.Genarray.map_file} for more details. *)
-
- val map_subfile: Unix.file_descr -> ('a, 'b) kind -> 'c layout ->
- bool -> int -> int -> int -> int64 -> ('a, 'b, 'c) t
- (** Memory mapping of a file as a three-dimensional big array,
- starting at a given file offset.
- See {!Bigarray.Genarray.map_subfile} for more details. *)
-
end
(** {6 Coercions between generic big arrays and fixed-dimension big arrays} *)