How to get the ACTUAL size of a table

Before you go click that “send reply” with your 9 cps of yours and say that table.getn and # exists for a solution, This is not what I mean.

Here is what i want to make:

i want to make some computer of terminal, that has limited ram and all that. But, # and table.getn would not fit this usecase.

Here is why:

Lets say I have my table called ram

local ram = {}

now lets say i add a string and numbers.

local ram = {}
-- generate stuff on ram
table.insert(ram, "s")
table.insert(ram, 55)
print(#ram)

Two issues:

  1. If i extend the stringor number, it would still count as one of the values in the array.
  2. Regardless it dosent get the size of the table either way.

So i want to get the size of ram (in kbs), is that possible?

Btw sorry if i poorly explained it.

So if I’m reading this right, you’re trying to get the filesize of a table?

1 Like

Yes

After a quick google search. You could test this and see if this does what you’re looking for, but I’m not sure if it does as I haven’t tried it.

1 Like

Genius solution but i want it to be in vanilla lua too.

But thanks alot

bro just use table.getn, simple

Please read the post before replying. They are asking for how to get a table’s size in bytes.

2 Likes

Oh, thats not possible in vanilla lua

2 Likes

A simple way to phrase this question would have been, “How much memory does a given table consume?”, but regardless, a search would have answered your question. Please refer to the following article:

Well “how to get the ACTUAL SIZE of the table” works too but some people misinterpret it, But thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.