Share via


Visual Basic Concepts

Setting Base Addresses for In-Process Components

In 32-bit operating systems, the code pages for an in-process component (.dll or .ocx file) are shared between processes that use the component, as long as the component can load at its base address. Thus three clients could be using the controls in your component, but the code would be loaded into memory only once.

By contrast, if the memory locations used by an in-process component conflict with memory locations used by other in-process components or by the executable, the component must be rebased to another logical memory location in the executable’s process space.

Rebasing requires the operating system to dynamically recalculate the logical memory locations where code and data are loaded. This recalculation slows down the load process, and code that is dynamically relocated generally cannot be shared between executables.

You can greatly improve your component’s memory use by choosing a good base address.

Setting the Base Address

To enter the base address for your component, open the Project Properties dialog box and select the Compile tab. The address is entered in the DLL Base Address box, as an unsigned decimal or hexadecimal integer.

The default value is &H11000000 (285,212,672). If you neglect to change this value, your component will conflict with every other in-process component compiled using the default. Staying well away from this address is recommended.

Choosing a Base Address

Choose a base address between 16 megabytes (16,777,216 or &H1000000) and two gigabytes (2,147,483,648 or &H80000000).

The base address must be a multiple of 64K. The memory used by your component begins at the initial base address and is the size of the compiled file, rounded up to the next multiple of 64K.

Your program cannot extend above two gigabytes, so the maximum base address is actually two gigabytes minus the memory used by your component.

Note   Executables will usually load at the 4 megabyte logical address. The region below 4 megabytes is reserved under Windows 95/98, and regions above two gigabytes are reserved by both Windows 95/98 and Windows NT.

Use a Good Random Number Generator

Because there is no way to know what base addresses might be chosen by other in-process components your users might employ, the best practice is to choose an address at random from the indicated range, and round it up to the next multiple of 64K.

If your company produces many in-process components, you may wish to randomly calculate the base address of the first, and then arrange the others above or below the first, thus guaranteeing at least that your company’s components will not have memory conflicts.