Sorting tables with no garbage (table.sort alternatives)
Hi all,
if you need to sort tables quite frequently you'll find that table.sort causes a lot of garbage memory. Here are two memory friendly in-place alternatives (parameter compatible to table.sort). Maybe some people finding this helpful: 1. Shell sort (around 1/3 slower than table.sort which is a quick sort implementation in lua): Code:
local tIncrements = { Code:
local tCnt, tCnt2, tSize; |
The only time table.sort() should be causing "garbage memory" is if you are creating a new sort function every time you call it instead of re-using a single function.
Bad: Code:
table.sort(my_table, function(a, b) Code:
local function MySortFunction(a, b) |
Yes, you're perfectly right, thank you...
|
Gooder:
Code:
local function MySortFunction(a, b) |
Indeed. :P
|
All times are GMT -6. The time now is 04:52 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI