|
Let's say I know I need to create a big table and I do not want rehashes tohappen when I am filling it. What is the best way in Lua to create the big table?Is there any way to create a big table with only the array or only the hashpart?This can be done with the C API but I am wondering if there is way in Lua.It seems not but maybe I missed something.I can only think about big constructors list in the source code - but thereis a limit on how big they can be right? Andrea
Well, about 2 years ago I posted a patch for Lua 5.3.5 that exposed a function that can
reserve memory for the array and hash part of a table. [1]The performance improvement can be significant when reserving the number of elements that are expected for the hash part of a table, for the array part this is negligible. Reserving avoids rehashing when the number of items in the hash part of the table grows
while filling the table. Would be nice to see a similar function in a future release of Lua. -- Jasper [1] http://lua-users.org/lists/lua-l/2018-12/msg00175.html