lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Did your original "scripting attempt" work?

A VM takes a bit of overhead just to support it's ability to translate
between the scripting language and the program.  When you make semi-typeless
variables you then have to use a union (or something similar) to handle it
(you could make all variables members of a class that can overload operators
so that, well, you get the idea....).

As for the multiple copies of the same script bit, why not just hold the
local info for each copy of the script that you would have made, then
literally load that info in before you run the single copy of the script -
like C++'s vtable for member functions in classes.  Load one copy of code,
use many individual instances of data.  Keep a vtable on the C++ side to
separate your data, and I believe there is a way to change global data in a
LuaState....  I might be WAY off base here.

Probably not very helpful, but I hope it sparks some ideas for you....

Rich

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Stuart
Middleton
Sent: Friday, September 12, 2003 9:17 AM
To: Lua list
Subject: Lua memory usage for games console



 Hi All,

We are currently evaluating lua as a replacement for our internal scripting
attempt. My initial evaluation (only 1 day) shows that each loaded script
uses a load of memory.

i.e.

xpos = 20.423987987234
ypos = 30.923874982343
zpos = 40.982374982734

function GetAllPos()
	return xpos+ypos+zpos;
end

function GetXPos()
	return xpos;
end

function GetYPos()
	return ypos;
end

function GetZPos()
	return zpos;
end

which is pitifully small (and does nothing useful) uses 822 bytes of memory.
I am using precompiled scripts with the debug info stripped. This memory
does not included the mem used to load the script in the first place.

As far as I can see its because of the over bloated structures inside lua.
For instance GCObject uses 72 bytes just because it's a union of common
types one of which being Proto which is 72 bytes long. So at a guess each
variable will be at least 72 bytes long?

Before I go rewriting how lua handles its internal structures or give up on
it completely I wondered if anyone out there has reworked the system to use
minimal memory.

As comparison a simple test script like this in our system would use about
250 bytes with new instances of the same script using < 100 bytes.

Any help would be much appreciated.

While I'm at it I have another question.
We will need to load multiple scripts, hundreds in fact, most of which would
be copies of each other. They all need to maintain their own global (or file
local) variables. Has anyone done this before? I guessed you would use
either the threading system or a new state for each (we are not
multi-threaded) but the overhead for a new system or even a new thread each
time is a bit over the top. Also our internal system was written so we could
load a script once and create instances of it with new variables but pointer
to the functions in just 1 copy of the byte code.

Any idea's

Hope you can help

Stuart Middleton (lua newbie)