[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Memory allocation of arrays
- From: Rodrigo Azevedo <rodrigoams@...>
- Date: Fri, 21 Jul 2017 08:21:04 -0300
Dear,
The memory allocation of "array" part of tables increases by a factor
of 2, as we can see from the program below
mem = function() return collectgarbage"count"/1048576 end -- Gbyte
t = {}
c = mem()
print("MEM",c)
count = 1
while c < 4 do
t[count] = c
c = mem()
if c > 1.5*t[#t] then print(c) end
count = count + 1
end
print("MEM",mem())
but this is very annoying when we are using many Lua states trying to
use each byte of many GB with very huge tables (many GB) concurrently.
But the code
f = function(n) return string.format("%d",n) end
t = nil collectgarbage()
t = {}
c = mem()
print("MEM",c)
count = 1
while c < 4 do
t[f(count)] = c
c = mem()
if c > 1.5*t[f(count)] then print(c) end
count = count + 1
end
print("MEM",mem())
does not have this annoying behavior, showing a more straight memory allocation.
Then, this seems to be an "implementation detail" that I would want to avoid.
Is this possible? How?
Thanks!
--
Rodrigo Azevedo Moreira da Silva