What is the difference between the types vector
, simple-vector
, array
and simple-array
?
I know that vectors are a subtype of arrays and cannot be multidimensional.
The "simple-" versions seem to be types, and the rest classes. So the types might be more complex, to specify the type.
Which type-specifiers should I use? What is the best way to specify a vector?
A vector is an one-dimensional array.
They are simple if they are not displaced, have no fill pointer, and are not expressly adjustable. A simple-vector also needs to be able to hold elements of any type.
Which type-specifiers should I use?
I guess that depends on what you want to do.
Rainer answered the positive part of your question.
Here is the answer to the normative part:
Which type-specifiers should I use?
You should not use any, unless you know very well what you are doing.
Type annotations in Common Lisp are optional; they are intended for the experts for the performance tuning. It is highly unlikely that you will ever gain any meaningful benefit from type declarations and you are highly likely to be hurt by them. E.g., if your type annotation is wrong you might get a segfault instead of an error message (when combined with unsafe code).
Additionally, the effect may be the opposite of what one might expect. E.g., using specialized arrays (e.g., (array double-float)
) to reduce memory footprint may result in an increased garbage collection because every array access may have to box a new double-float
.
Essentially, type annotations are usually micro optimizations which should be accompanied by careful profiling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With