1

I'm writing a log aggregator and I want to send the logs if it reaches a max byte size. Thus is there a way in Lua to get to know the size of the variable (active_batch size)?

local batch = {
    flush_timeout
    retry_count
    batch_max_size
    batch_count

    batch_to_execute = {},
    active_batch = { entries = {}, count = 0, retries = 0 }
}
Leszek Mazur
  • 2,443
  • 1
  • 14
  • 28
Nirojan Selvanathan
  • 10,066
  • 5
  • 61
  • 82
  • 2
    A variable doesn't have a byte size. An object might, but Lua doesn't have a way to tell how many bytes a table might represent. – Nicol Bolas Jan 21 '20 at 15:46

1 Answers1

1

You only can have total memory used by LUA by collectgarbage. In this case I think that storing string len and sum of it will work.

Leszek Mazur
  • 2,443
  • 1
  • 14
  • 28
  • 2
    Some notes. 1 Lua allocates memory for string only once. So if you have N exact same strings Lua creates only one copy of it. 2 There exists the lua-getsize module which allows to estimate Lua object size – moteus Jan 22 '20 at 09:13