Subject: Re: aref vs svref
From: Erik Naggum <erik@naggum.no>
Date: 1999/01/25
Newsgroups: comp.lang.lisp
Message-ID: <3126281048122906@naggum.no>
* David Bakhash <cadet@mit.edu>
| Let's say I define a class, `class-A', and I have an array of objects of
| type class-A. If class-A is a complex class, with lots of slots, etc, is
| it better to define the (1-D) array of type T so I can use `svref', or is
| it better to tell the compiler the truth, which is that the :element-type
| is really class-A (in which case it may sometimes be (or null class-A)).
| Sometimes it's not so clear if telling the compiler things is really a
| good idea.
I guess you're really asking whether a vector of class instances will be
a simple vector unless you have fill pointers, displacement, or make it
adjustable. the answer is yes. only a small set of types can be
expected to specialize the array type and all of them are built-in types.
the key is whether the object has to be referenced through a pointer or
not, or can reasonably be allocated a fixed-width slot in a vector. if
it cannot be allocated a fixed-width slot, it has to use a pointer.
you can probably find out by using UPGRADED-ARRAY-ELEMENT-TYPE on the
type and see whether it is T. if it is (and you do none of the other
stuff that requires an array header), you must get a simple vector.
of course, you know that you can find out whether a particular array is a
simple vector with SIMPLE-VECTOR-P.
#:Erik
--
SIGTHTBABW: a signal sent from Unix to its programmers at random
intervals to make them remember that There Has To Be A Better Way.