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.
* David Bakhash <ca...@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.
In article <wk7lubl3u1....@mit.edu>, David Bakhash <ca...@mit.edu> wrote:
>Hi,
>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.
It is probably best to have the model that everything in lisp is a reference. So an vector of T elements and a vector of CLASS-A elements essentially both hold references. The type information can be handy when Lisp wants to inference about what kind of reference will be produced by a call to SVREF.
It doesn't change the "size" of a each vector "entry". [ For immutable databstructures, (e.g., fixnums , floats , etc.) the implementatoin may do this. However, that isn't required. ]