From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA25194; Fri, 12 Jul 2002 14:54:54 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA25187 for ; Fri, 12 Jul 2002 14:54:53 +0200 (MET DST) Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.25.148.40]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g6CCsoj27335 for ; Fri, 12 Jul 2002 14:54:51 +0200 (MET DST) Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id g6CCsmSs022957; Fri, 12 Jul 2002 22:54:48 +1000 (EST) Received: from ozemail.com.au (ppp115.dyn1.pacific.net.au [61.8.1.115]) by wisma.pacific.net.au with ESMTP id WAA09824; Fri, 12 Jul 2002 22:54:46 +1000 (EST) Message-ID: <3D2ED196.2060104@ozemail.com.au> Date: Fri, 12 Jul 2002 22:54:46 +1000 From: John Max Skaller User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901 X-Accept-Language: en-us MIME-Version: 1.0 To: Oleg CC: caml-list@inria.fr Subject: Re: [Caml-list] Array.resize ? References: <200207112228.SAA02692@dewberry.cc.columbia.edu> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Oleg wrote: >Hi > >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, mailto:skaller@ozemail.com.au snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia. voice:61-2-9660-0850 ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners