[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Loadlib work 5,1
- From: David Burgess <dburgess@...>
- Date: Sat, 4 Sep 2004 01:13:12 +1000
> And is the unloading of dynamic libraries during run-time really
> necessary?
For Win32, yes.
while (condition) {
L=lua_open();
lua_pcall(); /* loads libraries */
lua_close(L);
}
A loop like the one above can slowly expand the number of Win32
handles, a slow resource eater. Methinks it is neccessary.because
although each LoadLibrary() will return the same HANDLE value, each
call will increment the DLL reference count. The MS ODBC libraries and
socket libraries (for example) have DllMain tidy up code that only
gets executed when the process unloads the DLL. If the Lua DLL does
not get unloaded then the DllMain exit code (for ODBC/Socket DLLs)
does not get executed. This has given me trouble in the past(Lua 4)
with LuaSQL.
I
> To unload the library when the app closes is much easier. We can simply
> put the handle in the registry (with an appropriate GC metamethod).
Please do.
This is what I do. Handles only get collected on lua_close(), but they
do get collected.
The table of handles is only used in win32 for various other functions
that use module handles.
On Fri, 03 Sep 2004 09:45:04 -0300, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> > so that libraries could be unloaded manually or when the app closes.
>
> To unload libraries manually seems quite dangerous. It is hard to know
> (manually) for sure that there are no more functions that use the
> library. One option is to add the handle as an upvalue in all functions
> from that library. So, when the last function is collected, the handle
> would be collected, too. (I think ET mentioned something like that
> sometime ago.) This works, but it adds some overhead on C functions.
> And is the unloading of dynamic libraries during run-time really
> necessary?
>
> To unload the library when the app closes is much easier. We can simply
> put the handle in the registry (with an appropriate GC metamethod).
>
> -- Roberto
>
--
db