[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Specifying a different userdata size for gc purposes?
- From: ddneilson <ddneilson@...>
- Date: Wed, 07 May 2008 02:43:54 -0600
Hi there,
I've a quick question. I'm currently building a userdata type that is
implemented as a pointer to a C++ class. However, as far as the lua
garbage collector is concerned the size of this userdata is
sizeof(MyClass*) -- the size of a pointer.
When the C++ class in question uses a lot of memory (think a class for
an image, for instance) the amount of memory being used by the program
and the amount of memory that lua thinks is outstanding to be gc'd can
be extremely out of whack (lua will see the multi-megabyte image as only
4 bytes, for instance). This wouldn't be a problem if you're only
creating a couple of these userdata in a lua program, but if you're
creating a lot of them (as local variables in a loop, for instance) then
it doesn't take very long at all to accumulate hundreds of megabytes of
uncollected garbage that lua thinks is only a couple hundred bytes.
What I'm wondering is if there's any way of telling the lua garbage
collector that this userdata is actually occupying more than 4 bytes?
The idea being that then the gc will have a more accurate idea of just
how much memory is being used for the purpose of deciding when to run a
collection cycle. Right now, I get around this with a liberal sprinkling
of collectgarbage("collect") calls throughout my lua code; but, that
seems like it rather defeats the purpose of a garbage collected environment.
Thanks,
Daniel