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 BAA09521; Fri, 12 Jul 2002 01:00:12 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA09508 for ; Fri, 12 Jul 2002 01:00:11 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (r-mi214-6a109.tin.it [62.211.4.109]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g6BN0AD27721 for ; Fri, 12 Jul 2002 01:00:10 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id D13912739C for ; Fri, 12 Jul 2002 01:06:59 +0200 (CEST) Message-ID: <3D2E0F93.6060708@baretta.com> Date: Fri, 12 Jul 2002 01:06:59 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 X-Accept-Language: it, en MIME-Version: 1.0 To: Ocaml 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) Ah, wait a minute. A vector is not an arraw. Whatever its implementation it only behaves like an array from a syntactic point of view: it defines the operator[] for array indexing, but it might as well be implemented as a list for all you know; however, the STL imposes constraints on the complexity of the different algorithms used to manage a vector. I have found the following definition of a vector: > A vector is a Sequence that supports random access to > elements, constant time insertion and removal of elements > at the end, and linear time insertion and removal of > elements at the beginning or in the middle. The number of > elements in a vector may vary dynamically; memory > management is automatic. This is much different from either a C array or an O'Caml array. Again, the issue is raised: do we need an OCaSTL? Alex ------------------- 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