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: -- (:)
From: John Max Skaller <skaller@o...>
Subject: Re: [Caml-list] Array.resize ?
Oleg wrote:

>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 ?
I might add that I have requested a variable length array, similar to a 
C++ vector.
It is possible to make one using pure Ocaml + a little Obj.magic. **
But it would be better if it were in the standard distribution.

[you need allocate initialise unused slots using Obj.magic ..
this is considered naughty :-]

Similar for Strings .. though IMHO module String should be deprecated:
we don't need Strings when we have Arrays.

John Max Skaller,
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.

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