Re: Accessing elements in foreign array of structs

"Erik Ronström (as erik dot ronstrom at doremir dot com)" <[email protected]> Sun, 12 Apr 2026 21:28:11 +0200
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>
> You mentioned that your foreign function requires a points array as an input argument. Where do these points originate?
>
> >From external functions? or from your running Lisp image? 
>
> And if they come from Lisp, then how do you expect to provide them without first allocating and stuffing their slot values?

Yes, I was being unclear: I *do* allocate the array on the lisp side, 
like in my example:

(let ((points (fli:allocate-foreign-object :type 'point :nelems 3)))
   ...

My problem is that I can't figure out how to set the slots in the foreign array elements.

It is probably some combination of foreign-aref, foreign-slot-value and 
dereference, but I can't make it work.


> [BTW… you are aware, aren't you, that using FLI:ALLOCATE-FOREIGN-OBJECT, without an accompanying FREE, will leak memory? I always use FLI:WITH-DYNAMIC-FOREIGN-OBJECTS and then inside of it I use FLI:ALLOCATE-DYNAMIC-FOREIGN-OBJECT. This surrounds the allocations with an UNWIND-PROTECT and a forced free, of sorts.]

Yes, I do free all objects! I just left it out for brevity :)

Erik

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html