|
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. Von: lua-l-bounces@lists.lua.org <lua-l-bounces@lists.lua.org> Im Auftrag von Gé Weijers On Thu, Oct 18, 2018 at 1:16 AM <michaelflad@clawdesign.com> wrote:
Doubling the size keeps the amount of work required to append an element to the array part of a table from becoming quadratic. Appending an element takes O(1) works amortized. |