From: Pierre Weis <Pierre.Weis@inria.fr>
To: jjgarcia@ind-cr.uclm.es (Juan Jose Garcia Ripoll)
Cc: caml-list@inria.fr
Subject: Re: Size of arrays
Date: Sun, 24 Jan 1999 23:31:42 +0100 (MET) [thread overview]
Message-ID: <199901242231.XAA12515@pauillac.inria.fr> (raw)
In-Reply-To: <36A9D5F0.F9215F45@ind-cr.uclm.es> from "Juan Jose Garcia Ripoll" at Jan 23, 99 03:00:16 pm
> I've noticed that OCaml imposes a very small upper limit in the size of
> arrays: 8Mb or so, I think. Can this limit be modified somehow?
[...]
No there is no way to modify this limit: it is wired into the data
structures representation algorithm. However, this limit is machine
dependant, and very high on a 64bits machine
(18014398509481983).
Anyway, it is not difficult to design an ADT that gives you large
arrays on a 32 bits machine:
(* Module Bvect of big vectors (length up-to max_int).
Access and assigment 2 times slowlier than regular arrays.
Iteration is as efficient as Array.iter. *)
(* bvect.mli *)
type 'a bvect;;
val make : int -> 'a -> 'a bvect;;
val length : 'a bvect -> int;;
val item : 'a bvect -> int -> 'a;;
val assign : 'a bvect -> int -> 'a -> unit;;
....
(* bvect.ml *)
type 'a bvect = 'a array * 'a array;;
let make len init =
if len <= Sys.max_array_length then (Array.make len init, [| |])
else (Array.make Sys.max_array_length init,
Array.make (len - Sys.max_array_length) init);;
let length (v1, v2) = Array.length v1 + Array.length v2;;
let item (v1, v2) i =
if i < Sys.max_array_length then v1.(i)
else v2.(i - Sys.max_array_length);;
let assign (v1, v2) i item =
if i < Sys.max_array_length then v1.(i) <- item
else v2.(i - Sys.max_array_length) <- item;;
let iter f (v1, v2) = Array.iter f v1; Array.iter f v2;;
(* Omitted, sub_vect, map_vect, ..., as in module Array. *)
Hope this helps,
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/
prev parent reply other threads:[~1999-01-24 22:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-01-22 19:10 Array interface question Brian Rogoff
1999-01-22 19:21 ` Pierre Weis
1999-01-22 20:05 ` Brian Rogoff
1999-01-23 10:47 ` Anton Moscal
1999-01-23 10:57 ` David Monniaux
1999-01-24 15:44 ` Jerome Vouillon
1999-01-24 21:36 ` Pierre Weis
1999-01-28 19:57 ` Brian Rogoff
1999-01-23 14:00 ` Size of arrays Juan Jose Garcia Ripoll
1999-01-24 22:31 ` Pierre Weis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199901242231.XAA12515@pauillac.inria.fr \
--to=pierre.weis@inria.fr \
--cc=caml-list@inria.fr \
--cc=jjgarcia@ind-cr.uclm.es \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).