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
[Caml-list] productivity improvement
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-07-11 (22:28)
From: Oleg <oleg_inconnu@m...>
Subject: [Caml-list] Array.resize ?

Is there an efficient way in O'Caml to append an element to an array ref?

let append_elt r x = r := Array.append !r [| x |];;

copies the contents of the whole array in its body, while e.g. C++ vector 
push_back in most cases won't (memory is reserved in chunks automatically, or 
it can be reserved manually)

IOW it seems strange to me that functions of arrays can change their contents 
but not their size, while functions of array ref's can do it, but 
inefficiently. How about 

Array.resize :  'a array -> int -> unit

or at least 

Array.resize: 'a array ref -> int -> unit ?

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