[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Heap usage and variable argument C functions
- From: Asko Kauppi <asko.kauppi@...>
- Date: Tue, 21 Dec 2004 12:43:58 +0200
21.12.2004 kello 05:55, Cory Bloyd kirjoitti:
I am assuming this does not apply to C functions called from Lua. C
functions do not inform the interpreter as to how many arguments they
expect so they technically always work in vararg mode. It is OK though
because they can interpret the parameter stack directly without needing
a temporary table. Am I correct?
Well, you can also think Lua functions (non-vararg) work the same as
the C ones. What I mean is, if you feed a function more params than the
prototype says, it won't complain (just ignore the extraneous params).
So, I would see C function binding just going this same path (and not
even being vararg-like). In practise, you are right. :)
I ask because we have a C function that will be called very frequently
from Lua and will need to accept a varying number of arguments. We are
yet another game development house adopting Lua. Therefore the time
spent in the garbage collector is a very sensitive issue for us.
I'm doing this all the time (having C func with varying params) and
it's not only efficient, but also very effective for the API
simplicity. Does the operator overloading thing (same function name,
"it'll know what you mean" ;).
Summarizing my understanding... The following is a complete list of
actions that involve garbage collectable allocation in Lua:
*Loading chunks of bytecode
*Creating tables, functions, strings, threads or userdata
*Calling Lua functions with variable parameters
Hmm.. changing variable values?
(string,threads,userdata,functions,tables) If the old reference is not
referred to from elsewhere, it'll eventually get gc'd.
You can avoid this by keeping an extra ref to everything you create, in
some dummy table. I would not. :)
always constructed incrementally. Therefore the collector could
possibly be triggered during a table construction because of the
fragmentation they induce.
Hmm.. (again). I'm not a Lua internals expert, but what would be gc'ed
if things are only added to the table? Fragmantation - what do you
mean by that?
No prob. This is the way things work; welcome to the community, too. ;)