The canonical way to efficiently store large numbers of integers is
(make-array the-size :element-type '(signed-byte 32))
or whatever. There are no guarantees, but CMUCL seems to store these as bytes rather
than as type t.
(make-array the-size :element-type '(signed-byte 64))
doesn't work; you gets get an element type of t. However, the smaller powers of 2
work also.
Be careful, ...
(make-array the-size :element-type '(byte 32))
also gives you an element type of t .
-dk
Mathias Broxvall wrote:
>
> Hello everyone,
>
> I am currenly porting a large project (a fuzzy robot controller/AI system)
> consisting of both C and lisp code to run under CMUCL and have encountered
> some difficutlies with foreign function calls and the way integers are
> handled within CMUCL. I hope someone can help me with this.
>
> The main problem is that in the lisp code is commonly giving arrays of
> integers and floats which the C functions return values in. For the floats it
> work good to do eg:
>
> C-code:
>
> void loc_update_robot(float pos83],float unc[128]) { .... }
>
> Lisp
>
> (alien:def-alien-routine ("loc_update_robot"
> loc_update_robot0) void
> (pos (* single-float) :in)
> (unc (* single-float) :in))
> (defmacro loc_update_robot (pos unc)
> `(sys:without-gcing (loc_update_robot0
> (system:vector-sap ,pos) (system:vector-sap ,unc))))
>
> And then call the function with global array of floats created using eg:
>
> (defvar *robot-unc* (make-array 128 :element-type 'single-float)))
>
> However, this method doesn't work for integers since the implemention of
> integers in CMUCL differs from ordinary C-integers which leads to some realy
> strange errors (the 2 lowermost bits are used as type and gc information?)
>
> What is the easiest way of handling arrays of integers. Since the code is
> running very often (the control loop cycle is < 100ms) I would prefer if
> possible not to do converstions between the lisp and C side. Is it eg.
> possible to somehow create and use "normal" 32bit integers in CMUCL?
>
> thankfull for any help you can give =)
>
> / Mathias Broxvall