Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

.NET

Faster DLL, Load! Load!


[This is Part I of a two-part series. Part II is available here.]

Load-time performance isn’t as critical an optimization now with many people using computers with CPU speeds north of 1 GHz, hundreds of megabytes of RAM, and faster hard drives. However, in some situations, load-time performance can still be a problem if the application uses many DLLs. In this issue of the Windows Q&A newsletter, we’ll take a look at how to optimize the load-time performance of just such an application.

First, it’s important to understand where a DLL is typically loaded into memory. Inside of every DLL is a base address—the memory address where the chunk of executable code will start. For executables, the default address is 0x400000, while for DLLs it is 0x10000000. Whenever you create a DLL in Visual Studio, the linker uses 0x10000000 as the base address by default. To see the base address of a DLL (or EXE), you can use the depends utility that comes with the SDK. Simply type “depends.exe <dll filename>” and you’ll see something like the following:


Figure 1: Showing the base address of a DLL.

Fortunately, this address can be overidden. The questions that come to mind include where do I override this value and what value do I use as an override?

To override the base address value for a DLL (assuming you have the source code), you can make this change in the Project properties\Linker\Advanced dialog:


Figure 2: Setting the base address via Project properties.

You can use any value you wish for the entry point (base address), but using an address that will be used by the EXE or another DLL will defeat the whole point of this exercise. So you need to specify an address that is available within your process space. Fortunately, Microsoft suggests the following convention for selecting addresses. Using the first letter of the DLL name, look to the right and select an address:

First Letter
Base Address
A–C
0x60000000
D–F
0x61000000
G–I
0x62000000
J–L
0x63000000
M–O
0x64000000
P–R
0x65000000
S–U
0x66000000
V–X
0x67000000
Y–Z
0x68000000

You might be wondering what you should do if you have multiple DLLs with the same first letter. A brute-force approach would be to evaluate each DLL’s size, then start with a given base address value (say, 0x60000000). Add the size of a DLL to the base address and use this new value as the next starting point. You must use the virtual memory size of the DLL, not its EXE file size. Again, we look at the output of depends.exe to get this size:


Figure 3: Determining the virtual memory size of a DLL.

The value I circled in red is the size of a DLL that I created that exports a single do-nothing function. Its size is listed as 0x3C000 (245760 in decimal). So, if I had another DLL for which I wanted to set the base address, I would add 0x3C000 to my initial starting base address and I’d be done.

In the next installment, we'll continue looking at this topic by considering how to create a reference file of fixed address for each DLL in a text file that can be used at link time, and how to use the Rebase.exe tool that comes with the SDK.


Mark M. Baker is the Chief of Research & Development at BNA Software located in Washington, D.C.
Do you have a Windows development question? Send it to [email protected].


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.