Suppose I declare an alien structure (assume (use-package :sb-alien)
thoroughout):
(define-alien-type a-struct (struct a-struct (foo unsigned-int)))
and an accessor:
(defun get-a-struct-foo (a-struct)
(declare (type (alien (* (struct a-struct (foo (unsigned 32))))) a-struct))
(slot a-struct 'foo))
This generates fast, efficient, non-consing code. If I remove the
declaration, I get calls to naturalize, which compiles up closures
every time I call get-a-struct-foo, and call to get-a-struct-foo ends
up consing about 250,000 bytes.
My question is, is there any better, more concise way to write the
type declaration? Preferably something that involves just saying I've
got a pointer to an a-struct, rather than having to actually write out
the nested list structure for the type. This is a very simple
example, and when wrapping real libraries, I often get nested
structures with many fields, leading to enormous declarations. Any
thoughts or ideas?
Cheers,
rif
|