Huge map and memory use

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Spessman
Prole
Posts: 9
Joined: Sun Oct 11, 2015 2:19 pm

Re: Huge map and memory use

Post by Spessman »

You need help using structs?
No, thanks.

But i have another problem.
I did it. Now my map splits into chunks, writes to files and can load.
And my function have a memory leak.

Code: Select all

--map - 1000x1000x1, chunk_size - 100
function map_splitOnChunks(map, chunk_size)
	local mapsW, mapsH = 1000/chunk_size, 1000/chunk_size
	local lastX, lastY = 1, 1
	local pus = 0
	for a = 1, mapsW do
		for b = 1, mapsH do
			local chunk = {}
			local CS_X, CS_Y = chunk_size, chunk_size
			if a ~= 1 then
				lastX = chunk_size*(a-1)
				CS_X = chunk_size+lastX
			elseif a == 1 then
				lastX = 1
				CS_X = chunk_size
			end
			if b ~= 1 then
				lastY = chunk_size*(b-1)
				CS_Y = chunk_size+lastY
			elseif b == 1 then
				lastY = 1
				CS_Y = chunk_size
			end
			for x = lastX, CS_X do
				chunk[x] = {}
				for y = lastY, CS_Y do
					chunk[x][y] = {}
					for z = 1, 1 do
						chunk[x][y][z] = map[x][y][z]
					end
				end
			end
			chunk = nil
			collectgarbage()
		end		
	end
	collectgarbage()
end
When i comment this function memory is ~30kb.
Otherwise, memory is ~220kb
I found source. This is:

Code: Select all

for a = 1, mapsW do
		for b = 1, mapsH do
		
		end
end
But why?
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Huge map and memory use

Post by bobbyjones »

You are creating tables. Tables use memory. The for loop alone probably not using too much.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests