Thursday, November 4, 2010

DLL Delay Loading

Tip -Use DLL delay loading to increase startup performance of an executable.

Details -Libraries are the way by which any system is built. We know that a library can be static or dynamic. In most of the situations, we use dynamic libraries. Usually when a loader program prepares an executable for execution, apart from other things, it will iterate the IAT (Import Address Table) of the executable and call the LoadLibrary() for each of the DLL found in the IAT. If an executable is linked to ten DLLs, then the loader will call ten LoadLibrary() calls. Additionally the same procedure will be done for each of the DLLs being loaded. In a big system with numerous executables that are linked to hundreds of DLLs, the startup performance will be affected by this DLL loading. In fact, the functions in these libraries may not be called by the executable during startup. Here we can save the DLL loading time by configuring candidate DLLs for delayed loading.

Delay load is a feature, that when used, will cause the DLL to be loaded only during the first invocation of any of its exported function. We can configure a DLL for delay load for both an EXE and DLL. This feature is invoked when the compiler builds the binary.

How To - The easiest way to do this is by using the /DELAYLOAD:dllname linker switch. This is supported starting from VC 6.0.

Higher versions of Visual Studio give more options such as programmatically specifying the DLLs for delay load. It also gives more flexibility such as unloading the delay loaded DLLs.


Posted By : Mohammed Nisamudheen S.

No comments:

Post a Comment