[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: [A important problem] A C module has its fast global state?
- From: Xavier Wang <weasley.wx@...>
- Date: Sun, 10 Jun 2012 16:15:35 +0800
hi list and Luiz,
these days I'm always think about something. I have a lower-level
binding runtime for Lua. this runtime is designed give some service to
real lua C module. I noticed I need some global state for that binding
(e.g. a ptrbox, a global module metatable, etc.), sometimes the global
state needn't very fast, but sometimes it does.
a long age I used string key in Lua registry, but Luiz said it's
faster using a pointer as key in Lua registry. so I have tried it. but
I found some problem I can not solve.
In fact, my lower-level runtime need work in these situations:
- it can used dynamic with a single lua State.
- it can used static and dynamic (means, more than one exists in your
program) with a single Lua state.
- it can used dynamic with multiply lua State in a single process.
- it can used static and dynamic with multiply lua state in a single process.
some of example:
- a module A, B, all static compiled with my runtime (say, O), used in
a single Lua state.
- a module A, B, with O, used in multiply Lua state.
- a module A with O in lua State1, and B in lua State2, now you
require 'A' in lua State2.
first of time I just use a static variable's address as this pointer,
but it will be a issue if you have A and B with different O, it means,
A has its own pointer box and so as B.
second I used a static pointer variable in runtime, first I find a
string key in Lua State, if it don't exists I used my own static
variable address, otherwise I used this value. in all cases I store
the pointer to static pointer variable so I only need query string key
once. but it don't work in example 3 above.
we have some feature of Lua to depend:
- one Lua State has one different registry (that is, depend Lua's
State (L) is safe)
- if all different O has same pointer value these is no problem. (that
is, we should find some invariant between possible O module)
- or, We just give up one of aspect: speed, or multiply lua State support.
this runtime is my lbind's runtime library:
https://github.com/starwing/lbind/tree/master/runtime it support
staticly compile into binding module, or used as a dynamic library.
the problem only occur in static compiled module.
hopes for a effective way to use fast rawgetp/rawsetp features, in the
situation we can not promise there only one symbol in program.