Browse thread
[Caml-list] productivity improvement
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Alessandro Baretta <alex@b...> |
| Subject: | Re: [Caml-list] Array.resize ? |
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