C++/VB - Optimize DLL load time

Asked By Danie
03-Jul-07 10:00 PM
Hi,

My application loads many DLLs using Loadlibrary. The number of the DLLs can
be as many as four hundred DLLs (in the same directory of the application). I
used the SDK rebase to rebase all the DLLs. Is there an API to get the
address of the loaded DLLs after it was loaded by the application? Also, any
advice about optimzing the DLL load time and run time is appreciated.
--
Thanks,

Daniel
ReBaseImage
(1)
DLLs
(1)
LoadLibrary
(1)
OptionArkady
(1)
Windows
(1)
Pietrek
(1)
Perforamance
(1)
E572023C533B
(1)
  Skywing [MVP] replied...
03-Jul-07 10:09 PM
The HMODULE value returned by LoadLibrary is actually the base address.  You
can cast it to a pointer-sized type and examine it that way.

You can also use the various functions to enumerate loaded modules (e.g.
PSAPI, Toolhelp32), which return the HMODULE (base address) for each mapped
image, though this is relative to the address space of the target process.

Beyond that, a debugger (e.g. WinDbg) should be able to provide you with a
list of loaded modules and their base addresses - in WinDbg, use `lm' for
that purpose.  Also, I believe Process Explorer (
http://www.sysinternals.com ) has an option to highlight rebased DLLs while
inspecting a process if you want to check if you have missed any that are
still getting moved at load-time.

--
Ken Johnson (Skywing)
Windows SDK MVP
http://www.nynaeve.net
  Doron Holan [MSFT] replied...
04-Jul-07 12:38 AM
regardless, 400 DLLs is not a perfomant design no matter what you do.
Strongly consider reducing the number of DLLs you are trying to load
overall, it will reduce memory fragmentation for instance.

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
  Arkady Frenkel replied...
04-Jul-07 02:55 AM
So my question here how many functions each dll have , seems to me not a lot
proposition of Doron )
Arkady
  Arkady Frenkel replied...
04-Jul-07 03:01 AM
Just to spread loading time, check /DELAYLOAD linker option
Arkady
  Danie replied...
04-Jul-07 12:26 PM
Thanks for your answers and suggestions. Note that we are the only users of
this software.
The  program calls LoadLibrary to load all these application specific  DLLs.
So DELAYLOAD linker option is not applicable to this case. Right?
Is it a good idea to let the application to rebase the DLLs using
ReBaseImage to the address that was returned by HMODULE value (only the first
time it starts) so the next time the application starts, it would load
faster? Will the address be the same every time the application starts? if
two process of the same application starts will the virtual address would be
the same?
Is it better to rebase the DLLs randomly using a hash function and a range
of addresses?

--
Thanks,

Daniel
  Arkady Frenkel replied...
05-Jul-07 03:28 AM
Oh, If you do that with LoadLibrary , you can do delay whenever you need, so
you don't need to use DELAYLOAD switch. OTOH why you need to rebase dlls
during run-time, do it during development process ( you can set base address
in properties ), so that ( rebase)  will not take time ( so that save
time-for-relocation * n-instances of your app )

Arkady
  Marc Sherman replied...
07-Jul-07 10:31 PM
Use rebase.exe instead of RebaseImage(), it's easier. Also, after rebasing
all your dll's, look at using bind.exe to make load time a little bit
faster. Matt Pietrek wrote a really good article about rebasing and binding
some years ago in MSJ or (MSDN Mag). Just google for his name and rebase and
bind.

Marc
  Danie replied...
09-Jul-07 11:02 AM
Thanks again.
I rebased all the DLLs. There can be up to four process in one system
loading about 450 DLLs, 100 system and others. The relocations were reduced
from 70% to 7% so I was pleased with this result. I read that relocated DLLs
cause more fault paging and prevent sharing (the dll code) the physical
memory with other processes.  So it optimizes the performance at run-time.
How can I measure this optimization? would perforamance monitor be the best
tool for that?

--
Thanks,

Daniel
Create New Account
help
Using legacy DLLs C++ / VB Hi, I am trying to build a very simple VC++ project in VS 2005 that links to some legacy DLLs. The DLLs were built with VC++ 6.0 (MFC 4.2). These DLLs work fine with VC++ 6.0 projects. My project compiles fine, but when it comes garbage? And how can I stop this from happening so that I can use these DLLs. I am not sure any sort of begging or bribing the vendor to rebuild the DLLs will work. Thanks! JAB VC Language Discussions ChTraitsCRT (1) StrTraitMFC (1) DestroyXYZ (1) CreateXYZ (1 we use to extend one or our products (written in VC++ 6.0) is through DLLs. If a DLL is detected, we load it and present the additional features to the thinking of source vs binary interface implications. By exposing source-level interfaces from binary units (DLLs) you introduce source-level dependency. It's as tightly coupled as if everything was compiled
converting to extension dll C++ / VB I have a large application with several inter-dependent dlls. These dlls were originally developed as mfc regular dlls. I am in the process of converting them to mfc extension dlls. I have changed _USRDLL to _AFXDLL, removed the CWinApp, and added DllMain. Now I am 1) By the way, there are some other complications with this application. Obviously since the dlls are inter-dependent we had to set up separate projects to first build libs for all of the dlls and then additional projects for linking the dlls. _USRDLL was changed to _AFXDLL in both the lib and lnk projects. DllMain was only added in the lnk projects. We also have separate resource dlls for each of these dlls. Try to create a new MFC extension DLL project and
Locations of Delay loaded DLLs C++ / VB Hi, I have an MFC application that needs to delay load some DLLs. I have mentioned the names of these DLLs in Linker-> Input-> Delay loaded DLLs and things work fine, but only if the DLLs reside in the EXEs path. I would like to load the DLLs from any other location, for example the temp path. Is there anything else that I need to do for this? TIA, JY VC Language Discussions DLLs (1) EXEs (1) Linker (1) MFC (1) Have a look on MSDN for the topic think that will point you in the right direction. Dave keywords: Locations, of, Delay, loaded, DLLs description: Hi, I have an MFC application that needs to delay load some DLLs. I