lua-users home
lua-l archive

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

I am facing in fact the same situation than with OpenCV : i would like to avoid modifying the C library itself. Up the now, i think that the easiest solution (even if not 100% perfect) is the proposal of Roberto (ie calling the lua_gc(STEP, x) during picture allocation to 'speedup' the gc). At the end, and after reading all your contributions, i think that the perfect solution still remains the integration of 2 new actions in the lua_gc call, allowing to increase/decrease externally the LUA internal memory counter.

Anyway, thansk for all your contributions, it's clearly very helpful.

Le 02/09/2010 23:12, Michal Kottman a écrit :
On Thu, 2010-09-02 at 16:58 -0400, Ted Unangst wrote:
On Thu, Sep 2, 2010 at 4:47 PM, Peter Cawley<>  wrote:
My proposal is that the current image-related code is taken, and then
the calls to malloc/free which deal with the large buffer are replaced
with calls to some generic allocator. Then the above Lua-based
allocator is used as the generic allocator...
Very interesting.  Thanks, that's a consequence I hadn't thought of.

I have a similar problem - I am currently creating a binding for the
OpenCV library. This solution cannot be applied in my case, because I
cannot (and do not want to) modify the library. A common pattern in
OpenCV is this (this is how I imagine the binding):

while not finished do
	local img = cv.RetrieveFrame(cam) -- retrieves image from cam
	-- do some processing

A full color image takes about 230K, and imagine 15fps - that is a lot
of data. Yes, I could force the end user to call img:Release() after
processing, but I want to spare him this step.

Since I cannot force the library to use my custom allocator (and the
image is allocated inside the library), I have to use boxed userdata,
containing a pointer to the image - and Lua sees that as only 4/8 bytes,
which may cause memory problems after some time.

Sylvain FABRE
Fixe: 09 72 11 30 24
Mobile: 06 30 12 72 34
Fax : 09 72 11 10 71