Is there a (simple) way to get memory usage in a Lua table?

I would like to know how much memory is used by the Lua table - without repeating the contents of the table and counting the usage. Is there a Lua 5.1 feature or a third-party library that could help with this.

+4
source share
3 answers

You can control the Lua memory usage by calling collectgarbage("count") or gcinfo( ) in the appropriate places in the entire code (for example, before and after insert operations). There is no trivial way to get the size of a table.

+7
source

There is no function for this task. why do you want to do this? What are you trying to achieve?

+2
source

Wouldn't something like this or this help?

2016 Update: see also: http://www.lua.org/wshop15/Musa2.pdf

+1
source

Source: https://habr.com/ru/post/1304351/


All Articles