Domanda

My Lua program starts by declaring a multidim table:

function love.load()

-- változók deklarálása

Maximum_X = 32                  -- a teljes játéktér mérete
Maximum_Y = 16

i = 0                           -- ciklusváltozók
j = 0

-- játéktér létrehozása

MapTable = {}

for y = 1,Maximum_Y do

    local row = {}

    for x = 1,Maximum_X do

        row[x] = 2          -- table.insert helyett
    end

    MapTable[y] = row       -- table.insert helyett     
end

end

And then, for an experiment, I do the element declaration for every possible frame.

function love.update(dt)

    for y = 1,Maximum_Y do

        local row = {}

        for x = 1,Maximum_X do

            row[x] = 2          
        end

        MapTable[y] = row           
    end

end

Theoretically, it creates 16 row = {} empty tables and uploads them with values in every frame, which means creating and uploading hundreds of new tables in each seconds. And there's even more operations and uploaded tables!

However, I couldn't see any increasing neither in RAM usage nor processor usage. What's the reason? Isn't

È stato utile?

Soluzione

The answer have come from Mud:

You should see minor blips in both CPU and memory. Lua's memory consumption will vacillate up and down as garbage (memory taken up by dead, inaccessible objects) accumulates and is then collected. But you shouldn't see that much here; you're not pushing it at all. Imagine how many tables are created per frame in in World of Warcaft client with 50 addons running during a 40 man raid fight...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top