Python startup seems slow... (NT)
Jason Taylor
jasont at wellmed.com
Thu Jan 27 15:44:35 EST 2000
I copied the following from the MSDN Library, October 1999.
-----------------
Delay-Loaded DLLs
-----------------
Earlier, we discussed the high expense of a page fault relative to a CPU
cycle. We also pointed out loading a lot of unnecessary code can cause
page faults during a program's operation as well as slowing the
program's initial load. Aside from keeping your code small to begin with
by careful design and intelligent use of the compiler's optimizations,
you can help to avoid this problem by loading code only when needed.
Windows has always supported dynamic link libraries (DLLs) and dynamic
function loading. Unfortunately, calling LoadLibrary and GetProcAddress
to load a function and balancing LoadLibrary calls with FreeLibrary
calls are somewhat tedious and error-prone tasks for developers.
The Visual C++ linker now supports the delayed loading of DLLs in a way
that's almost transparent. You can call functions from your code as
though they are statically linked and specify the /delayload:<dllname>
linker switch for each DLL you do not want loaded with the .exe. You
also must link to Delayimp.lib, which contains the delay load helper
routines. The linker generates a load thunk for imported functions in
delay-loaded DLLs.
A thunk is a short writeable code block that contains a function
pointer; Windows uses thunks to implement code relocation and to bridge
between 16-bit and 32-bit functions. The thunk we're talking about here
is what enables transparent delayed loading. It is initially set to call
the delay-load helper routine.
So, when your code first uses a DLL that has been marked for delayed
loading, the delay-load helper function is called. It checks the stored
handle for the DLL, sees it has not been loaded, and brings it into
memory with LoadLibrary. On the first use of each function in the DLL,
the helper function retrieves its entry point with GetProcAddress and
saves it in the thunk. On subsequent uses of the function, the function
is called directly from the stored pointer in the thunk.
You can explicitly unload delay-loaded DLLs after you are done with them
by calling the following:
__FUnloadDelayLoadedDLL
It is not necessary to do so, however.
More information about the Python-list
mailing list