Re: unboxed structure fields (or class slots)

"Yuri Davidovsky (as work at disclosure dot ie)" <[email protected]>
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>

> On 7 Jan 2026, at 12:12, Tim Bradshaw (as tfb at tfeb dot org) <[email protected]> wrote:
> 
> There are several easier ways than using the FLI, all of which come down to using a double-float array to hold the values.
> 
> The reason I'm asking is because I've been thinking about generalising my struct-of-arrays tool (whose purpose is to avoid this problem for implementations where it happens, amongst others).  I'm assuming LW can't do this.

This approach of using struct of arrays (rather than arrays of structs, or classes) is a common optimisation technique in high throughput applications, like games and graphics (think of particle animation), so you are not doing anything wrong here, it is an expected evolution, even in lower level programming languages. Working with unboxed values on an instance alone will likely not give you the best possible performance.

I think something like 

(with-slots (slot-a slot-b slot-c) object
  (declare (type double-float slot-a slot-b slot-c))
  :body)

might work well enough for the purpose of getting rid of boxing in a lexical context, but the boxing obviously will be there on the context entry/exit level yet it may work well enough if you are doing some substantial amount of computation in-between. 

But the thing is, if we take OOP languages, class objects are passed by reference there typically, so even if they do hold numeric values in their raw form, you will have to deal with pointer lookups, which is less than ideal, boxed or unboxed. So yes, using packed arrays is the way to go in my opinion, regardless of whether you are using lisp, or C++.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.