[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Lua memory usage for games console
- From: "Richard Ranft" <rranft@...>
- Date: Fri, 12 Sep 2003 17:00:28 -0700
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....
[mailto:email@example.com]On Behalf Of Stuart
Sent: Friday, September 12, 2003 9:17 AM
To: Lua list
Subject: Lua memory usage for games console
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.
xpos = 20.423987987234
ypos = 30.923874982343
zpos = 40.982374982734
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
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.
Hope you can help
Stuart Middleton (lua newbie)