VB COM Performance Tip (part 1): Specify the Base

June 16, 2004

For those of us still using VB, here’s a performance tip that is rather simple, but often overlooked. Specify a DLL base address!

What’s a “Base Address?”
Every DLL, written in C, C++, or VB (or any other language that supports it), has a default base address. An address specified in the header that tells Windows where it would prefer to be loaded into memory.

Why are they important?
If more than one DLL specifies the same base address, then Windows has to relocate one of them. Relocation involves many steps, including finding an empty memory location, and changing the pointers of every function definition and every function call within the DLL’s definition. This takes time and slows the loading of the DLL. It’s easy to see that once several DLLs need to be relocated, application startup slows significantly.

By default, a DLL’s base address is set to &H11000000 for VB and 0x10000000 for VC++.  So you can see that if you allow the default to remain, and create several DLLs for use by the same application, you will run into collisions quickly.

What can I do about it?
In Visual Basic 4, 5, and 6, the configuration for a DLL’s base address is in the Project Properties on the “Compile tab” toward the bottom.

In Visual C++, it’s a little harder to find (as most VC settings are). Open the Project Settings dialog through the menu Project->Settings. Then, under the “Link” tab, select the “Output” category. That is where the “Base Address” field is.

Change this value to any valid address (divisible by 64K pages). Be careful to choose one that is not only unique for all your DLLs, but also any other DLLs that your applications will use.

Also, be sure to leave enough free memory space between them so that they don’t bump into each other due to size.  For instance, if you have a DLL that is 129K in size, do not set the base address of another DLL to be 128K more than it’s own base address.

What I like to do, is to take my initials, map them to their phone keypad equivalent 396 then add a 2 digit hex number in sequence 01 02 03 … 0A … B4, etc.

That’s all there is to it.

Simple, isn’t it? Unfortunately, many developers don’t know it’s there, don’t know what it’s for, or don’t think it matters. Once you’ve set all your addresses and recompiled, you should notice an appreciable performance increase. Results will, of course, vary. Don’t forget to allow for system DLLs as well. One of the best ways to see what’s loaded is to use one of the many utilities for viewing loaded processes. I’ve found this utility to be quite useful.

Examples abound much more than I can fit in this entry, so search the web. Or, check out these additional resources: