lua-users home
lua-l archive

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


On 03/01/2014 20.37, Tom N Harris wrote:
table.concat and/or the C-level luaL_Buffer can be useful to reduce
>memory usage in these cases.
The VM concat instruction is very efficient so a chained .. is no worse than
table.concat. Where you get in trouble is building a string piecemeal in a
loop.

Yes, I am aware that table.concat and luaL_Buffer are not equivalent (that's why I wrote "and/or": convenience depends on the operation).

    function GCAndShow(prompt)
      local before = collectgarbage "count"
      collectgarbage"collect"
      local after = collectgarbage "count"
      io.write(string.format('%s: %.1fKiB (%.1fKiB garbage)\n',
                             prompt, after, before-after))
    end

By the way, I noticed that calling collectgarbage() only once, with 'collect' implied by default, does not always seem to perform a complete collection in Lua 5.1.

--
  Enrico