lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Anyway, the one thing you can do is to provide two ways of
> deallocation: one via GC, and one via a custom call which leaves the
> userdata floating around but deallocates the large buffers. At GC time
> you simply check if the buffers are still allocated or not.

Yep, good point. But this requires more than one destructor for the same
object, which might confuse the users of your C/C++ parts.

Another solution is to explicitly activate the garbage collector just
before you launch a function that will allocate large amounts of memory.
This way you can be sure that memory will be in its best state before you
start allocating heavily.

FYI: I have just checked the Python/C API, there is nothing better. If you
allocate your own structs in a C extension without using the Python
dedicated functions (PyMem_*), your stuff goes unnoticed by the GC. There
is no way to tell the Python GC about the true allocated size of your
objects beneath the top-level wrappers.

-- 
Nicolas