Log In  


Hi, I was wondering how to interpret the output from the stat function.

I created this simple program and run it:

function _update()
end

function _draw()
	cls()
	draw_debug()
end

_min_mem = 9999
_max_mem = 0

function draw_debug()
	if (true) then
		local _cpu = stat(1)
		local _mem = stat(0)
		local _cpu_c = 6
		local _mem_c = 6

		if (_mem < _min_mem) _min_mem = _mem
		if (_mem > _max_mem) _max_mem = _mem

		if (_cpu > 0.8) _cpu_c = 8
		if (_mem > 250) _mem_c = 8

		print("cpu ".._cpu,0,8,_cpu_c)
		print("mem ".._mem,0,16,_mem_c)
		print("mem min ".._min_mem,0,24,6)
		print("mem max ".._max_mem,0,32,6)
	end
end

This program runs for a while counting memory up and down (garbage collection from switching between editor and game mode?) and freezes on a fixed number from 20 to 45 after a while.

In my game I reach somethling like mem min = 94 and mem max = 268 and it continually fluctuates up and down. In the manual it states that this is a number in the 0..255 range, but I have not encountered any out of memory errors.

The question is how these values relate to the pico-8 runtime and the meaning of these numbers. As far as I can see, the CPU is the pico-8 emulated CPU and is a clear limit to keep an eye on. But for the memory, I don't know if this is related to the "virtual memory" of the console or if it is just a reflection of the OS and LUA runtime. In the latter case, how do you monitor your upper memory limit?



1

The Lua state uses a separate memory of 512k with a custom memory allocator used to keep track of size. The stat(0) return value is in k -- it used to be 256k and I forgot to update the manual.

The behaviour you're seeing is the garbage collector working because each time a unique string is generated in Lua, it requires a separate allocation. When the Lua state memory goes over 512k, a garbage collection is first attempted before falling back on the out of memory error -- but in this case that limit is not being reached as a GC is also invoked periodically I think.


Ok, thanks for clarifying!

Just a small suggestion, include the memory spec in the :: Specs section :)



[Please log in to post a comment]