What is DLL base address

  • Thread starter Thread starter Newish
  • Start date Start date
N

Newish

Hi

Regarding DLL base address:

1) What does it mean?

2) Should it ever be changed?

3) What are the rules to change it?

It defaults to &H00400000.

Regards

Newish
 
Hello,
Regarding DLL base address:
1) What does it mean?

A base address for a DLL is the virtual memory address into which it gets
loaded by default.

If I simplify things somewhat, all 32-bit Windows applications have a 2GB
memory space. When your application starts, this virtual memory space is
created by the operating system (OS), and it is virtual in a sense that
multiple processes can inside their address space refer to memory locations
with the same addresses, but the OS makes sure there are no actual
collisions.

Now, every EXE needs one or more DLLs, often the count can be something in
the range of 30-50 DLLs, most of which are OS DLLs. Each of these DLLs has a
base address, which, as I mentioned is the memory address into which it gets
loaded by default. Since two DLLs cannot be loaded into the same address,
the OS much "rebase" the DLL that is loaded if it has the same base address
as another DLL. This is a relatively slow operation.

Matt Pietrek has written an article about this to the May 2000 issue of MSDN
Magazine:

http://msdn.microsoft.com/msdnmag/issues/0500/hood/default.aspx
2) Should it ever be changed?

Since "rebasing" is costly, the answer is in yes, it should be changed.
However, it is arguable whether changing the base address actually has any
(real world) effect in the performance of your application. Sure, the effect
can be measured, but since you cannot know in advance which address would be
"collision-free" (since you can't control the base addresses of all those OS
DLLs), it is often a hit-and-miss thing.

So if you are writing a basic .NET application with one of two DLLs
(libraries), it probably doesn't make any difference to keep the default
values versus to change it. But if you have a big application with dozens of
libraries and performance is critical, consider changing the default values
of all your DLLs to unique values.
3) What are the rules to change it?

See the documentation of the /baseaddress command-line option for the C#
compiler:

http://msdn2.microsoft.com/en-us/library/b1awdekb.aspx

Hope this clarifies the situation.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
(e-mail address removed)
http://www.saunalahti.fi/janij/
 
1) This is the memory address it will attempt to load in first.
2) Not so much in .NET (this group), but there are definitely reasons to
change in traditional VB, where having each DLL at a different address will
reduce start up time of the app as it does not spend the time finding a good
address to store the DLL in memory.
3) If you are in VB 6, I would always change it. I do not have rules in
front of me (offline at the time I am typing this), but it should be easy
enough to find a base address project still and download (codeplanet.com is
where I think I have seen one).

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com/

*************************************************
Think Outside the Box!
*************************************************
 
jani:

You are correct for unmanaged stuff but this is not the case with JIT
compiled code.

The situation will also arise if you are using ngen .. but again rebasing is
not a major concern with JIT compiled code.

Cheers,

Greg
 
Back
Top