[Openmcl-devel] FFI question: passing aligned pointersfa
artem.mironov at gmail.com
Wed Dec 8 00:59:40 CST 2010
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)))
(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.
More information about the Openmcl-devel