[Openmcl-devel] FFI question: passing aligned pointersfa
Artem Mironov
artem.mironov at gmail.com
Tue Dec 7 22:59:40 PST 2010
Hello Gary,
On Tue, Dec 7, 2010 at 10:50 PM, Gary Byers <gb at clozure.com> wrote:
>
> And in this code as it's written, the compiler has no way of knowing that
> the function IOQ-NEW will always return a pointer, and the function's
> pretty much obligated to always return a boxed object.
>
>
>> (defun ioq-new (flags) (external-call "ioqnew" :int flags :address)
>
> What if this was written as a macro instead ?
>
> (defmacro ioq-new (flags) `(external-call "ioqnew" :int ,flags :address))
>
> (In many cases, you could get a similar effect by declaiming IOQ-NEW
> to be INLINE before defining it. In this case, the macroexpansion
> does a better job of avoiding boxing an address just so that it can
> be unboxed and stored in a stack-consed MACPTR object.)
>
> If you don't somehow make the pointer-creating operation (the EXTERNAL-CALL)
> visible to the compiler, there isn't much that it can do to avoid the
> boxing (that's necessary in general) in some specific case.
>
I rewrote my like this
(defmacro with-ioq ((var) &body body)
`(with-macptrs ((,var (external-call "ioqnew" :address)))
(unwind-protect
(progn , at body)
(external-call "ioqfree" :address ,var :void))))
and it does stack-consing indeed.
>
> And they have well-defined extents (lifetimes), and are therefore good
> candidates for stack-allocation.
>
Well, I see. I need to redesign some parts of my code.
Thank you clearing this to me.
--
Best Regards
Artem
More information about the Openmcl-devel
mailing list