[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Array or Vector?
From: |
Drew Adams |
Subject: |
RE: Array or Vector? |
Date: |
Wed, 10 Sep 2008 08:57:31 -0700 |
> When, in Emacs Lisp, is it preferrable to use a list over a vector and
> vice versa?
>
> My guess is
> - vector: for fast static sequences
> - list: for dynamically growing sequences
Yes (growing, shrinking, ...). And array, not necessarily vector.
See Elisp manual, node Sequences Arrays Vectors:
An "array" is a single primitive object that has a slot for each of
its elements. All the elements are accessible in constant time, but
the length of an existing array cannot be changed. Strings, vectors,
char-tables and bool-vectors are the four types of arrays.
A list is a sequence of elements, but it is not a single primitive
object; it is made of cons cells, one cell per element. Finding the
Nth element requires looking through N cons cells, so elements farther
from the beginning of the list take longer to access. But it is
possible to add elements to the list, or remove elements.
The Elisp manual is your friend.