Repository navigation
Constant structures/tables #239
ariankordi
started this conversation in
Ideas
Replies: 1 comment
|
Currently The closest I got to this being a limitation in my projects was in DataMatrix.fu which isn't that bad IMO and in most target languages has a smaller memory footprint than AOS. I did not originally plan const Foo[] Bar = {
{ Baz = 42, Quux = 1337 },
{ Baz = 67, Quux = 6502 }
};? |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Often it’s useful to have lookup tables with named values, like in these snippets:
As far as I understand, Fusion doesn’t support defining these as constants.
The alternatives I use are either:
On a similar topic, it looks like multidimensional arrays can’t be constant either. Examples of this:
The way I work around this is to flatten the arrays to be linear.
For example, if each item is a four-element float, then all of the floats would instead be part of a single array.
Then, calculate the start/end manually when you obtain the values. It's straightforward if you are already familiar with how arrays get laid out in memory, but a bit unintuitive if you don't.
For my port of FFLiDatabaseRandom where the sizes of some arrays vary, I used a second "index" array like this:
(Hopefully this makes sense)
There is a case to be made that doing it this way can be more optimal for languages like JS, where each Uint8Array has to be constructed one by one.
The property names may also add up to the total (uncompressed) code size. Look at jsQR.min.js as-is, and notice how much room these take:

Compare that to the same code minified with Google Closure Compiler which mangled all of the property names:

(Closure Compiler is not usable on most codebases, and the rest of the minifiers don't mangle like this.)
But, I guess the choice to do this or not should be up to the individual + this cost certainly doesn't appear in places like C++.
IMO I could go without either constant multi-dimensional arrays or structures, though it gets more annoying to not have the latter.

This is something I just implemented the other day, which you can tell it would've been nice to have structures for.
Let me know your thoughts on the matter, or if anybody else has run into a similar limitation while trying to implement something in Fusion. Thanks.
All reactions