Next: 5.11.9 Specialized Structure Slots
Up: 5.11 Numbers
Previous: 5.11.7 Floating Point Efficiency
Common Lisp supports specialized array element types through the
:element-type argument to make-array. When an array has a
specialized element type, only elements of that type can be stored in
the array. From this restriction comes two major efficiency
advantages:
- A specialized array can save space by packing multiple elements
into a single word. For example, a base-char array can have
4 elements per word, and a bit array can have 32. This
space-efficient representation is possible because it is not
necessary to separately indicate the type of each element.
- The elements in a specialized array can be given the same
non-descriptor representation as the one used in registers and on
the stack, eliminating the need for representation conversions when
reading and writing array elements. For objects with pointer
descriptor representations (such as floats and word integers) there
is also a substantial consing reduction because it is not necessary
to allocate a new object every time an array element is modified.
These are the specialized element types currently supported:
bit
(unsigned-byte 2)
(unsigned-byte 4)
(unsigned-byte 8)
(unsigned-byte 16)
(unsigned-byte 32)
base-character
single-float
double-float
Some versions of CMU Common Lisp also support the following specialized element types:
(signed-byte 8)
(signed-byte 16)
(signed-byte 30)
(signed-byte 32)
Although a simple-vector can hold any type of object, t
should still be considered a specialized array type, since arrays with
element type t are specialized to hold descriptors.
When using non-descriptor representations, it is particularly
important to make sure that array accesses are open-coded, since in
addition to the generic operation overhead, efficiency is lost when
the array element is converted to a descriptor so that it can be
passed to (or from) the generic access routine. You can detect
inefficient array accesses by enabling efficiency notes,
see section 5.13. See section 5.10.3.
Next: 5.11.9 Specialized Structure Slots
Up: 5.11 Numbers
Previous: 5.11.7 Floating Point Efficiency
Raymond Toy
Mon Jul 14 09:11:27 EDT 1997