Re: Pushing a UserData pointer?
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Pushing a UserData pointer?
- From: Chris Marrin <chris@...>
- Date: 2005年5月16日 20:49:29 -0700
Rici Lake wrote:
...
That's a cool idea. You could even stash a reference count in the
userdata before the actual object itself, and then let Lua do all the
memory management (aside from maintaining the reference count, of
course). That would allow a standard memory management regime for both
shared objects and objects only referenced by Lua.
I'd use a fully-weak table rather than a weak-valued table; it would
have much less impact on gc.
yes, a weak table worked well when I was using it. But it was two table
lookups. Seems to me that a lua_pushuserdata() implementation beats all
that to death (at least in my test cases so far). And, if you use an
opaque handle for the userdata rather than a void*, it can be as type
safe as passing around the lua_State.
I have to say that the trick of combining the userdata with the C++
instance data by overriding the new operator in C++ is incredibly cool.
Now I have one structure that can be used by both C++ and Lua and
lua_pushuserdata() allows it to be totally efficient. Thanks to Ben for
that hack!
--
chris marrin ,"",ドル
cmarrin@arch.sel.sony.com b` $ ,,.
(408) 955-3049 mP b' , 1$'
Sony ,.` ,b` ,` :$$'
,|` mP ,` ,mm
,b" b" ,` ,mm m$$ ,m ,`P$$
m$` ,b` .` ,mm ,'|$P ,|"1$` ,b$P ,` :1ドル
b$` ,$: :,`` |$$ ,` $$` ,|` ,$,,ドル`"$$ .` :$|
b$| _m$`,:` :1ドル ,` ,$Pm|` ` :$,ドル..;"' |$:
P$b, _;b$$b1ドル" |$$ ,` ,$$" ``' $$
```"```'" `"` `""` ""` ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'