lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 20 Oct 2018, at 9.06, <michaelflad@clawdesign.com> <michaelflad@clawdesign.com> wrote:

An array that doesn’t automatically but intentionally resize is easily extended

into one, with the automatic/current behaviour, and it needs very little additional

code.

But given the current version, you can’t do it the other way around, you’re

forced to waste the resources while there could be a version where it’s optional

and you, as the developer, should be the one knowing which one better fits your

current needs.

Also besides the waste of memory it also can trigger a series of reallocs while you

initially fill your array.

 

And yes, this is one of the very few parts where I think the language could

and should be extended, as it’s such a fundamental part and in (of course

my personal experience) way more than 50% of the situations where an

array is the data struct of choice, it’s actual (max)size is/can be known upfront.


I also think arrays are so common they could benefit from language level support.

In case you missed it, some time ago I wrote a proof of concept patch for array subtype + new syntax for array construction. The patch outlined one way to implement true arrays without making non-array code run any slower. There’s also some benchmarks which show significant perf improvement over regular Lua tables.

There was some discussion on this list about it, check out the archives if you’re interested.

Write up & code here:

https://github.com/petrihakkinen/lua-array

Cheers,

Petri