[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: using light userdata to keep full userdata alive?
- From: Asko Kauppi <askok@...>
- Date: Wed, 9 Jan 2008 02:47:22 +0200
I would put the light userdata into registry, pointing to the real one.
LUA_REGISTRYINDEX[ light_ud ] = real_ud
Once you don't need a certain light userdata any more, its registry
entry should be cleared.
When all registry entries are cleared, the full userdata becomes
Norman Ramsey kirjoitti 9.1.2008 kello 0:15:
I have a full userdata that includes a pointer to a large array.
I would like to be able to expose that array and individual elements
of the array as light userdata, for very efficient access.
But this means these light userdata need to prevent the full userdata
from being garbage-collected, which would cause the arrays
to be unmapped and the light userdata to be meaningless.
The only way I can think of to do this is to use a weak table
in which both keys and values are weak and the light userdata is
the heavy userdata is the value. Is this the correct approach?
Are there other possible approaches?