Condividi tramite


Visual Basic Concepts

Compiling Your Project to Native Code

If you have the Professional or Enterprise edition of Visual Basic, you can compile your code either in standard Visual Basic p-code format or in native code format. Native code compilation provides several options for optimizing and debugging that aren't available with p-code.

P-code, or pseudo code, is an intermediate step between the high-level instructions in your Basic program and the low-level native code your computer's processor executes. At run time, Visual Basic translates each p-code statement to native code. By compiling directly to native code format, you eliminate the intermediate p-code step.

You can debug compiled native code using standard native code debugging tools, such as the debugging environment provided by Visual C++. You can also use options available in languages such as Visual C++ for optimizing and debugging native code. For example, you can optimize code for speed or for size.

Note   All projects created with Visual Basic use the services of the run-time DLL (MSVBVM60.DLL). Among the services provided by this DLL are startup and shutdown code for your application, functionality for forms and intrinsic controls, and run-time functions like Format and CLng.

Compiling a project with the Native Code option means that the code you write will be fully compiled to the native instructions of the processor chip, instead of being compiled to p-code. This will greatly speed up loops and mathematical calculations, and may somewhat speed up calls to the services provided by MSVBVM60.DLL. However, it does not eliminate the need for the DLL.

To compile a project to native code

  1. In the Project window, select the project you want to compile.

  2. From the Project menu, choose Project Properties.

  3. In the Project Properties dialog box, click the Compile tab.

    Figure 8.6   The Compile tab in the Project Properties dialog box

  4. Select Compile to Native Code.

    Visual Basic enables several options for customizing and optimizing the executable file. For example, to create compiled code that will be optimized for size, select the Optimize for Small Code option.

    For additional advanced optimization options, click the Advanced Optimizations button.

  5. Select the options you want, then click OK.

  6. From the File menu, choose Make Exe, or Make Project Group.

The following table describes the native code options for optimization.

Option Description
Assume No Aliasing (Advanced Optimization) Tells the compiler that your program does not use aliasing. Checking this option allows the compiler to apply optimization such as storing variables in registers and performing loop optimizations.
Create Symbolic Debug Info Produces a .pdb file and .exe or .dll file containing information to allow for debugging using Microsoft Visual C++ 5.0 or another compatible debugger.
Favor Pentium Pro(tm) Optimizes code to favor the Pentium Pro(tm) processor.
No Optimization Disables all optimizations.
Optimize for Fast Code Maximizes the speed of .exe and .dll files by telling the compiler to favor speed over size.
Optimize for Small Code Minimizes the size of .exe and .dll files by telling the compiler to favor size over speed.
Remove Array Bounds Checks (Advanced Optimization) Disables Visual Basic array bounds checking.
Remove Floating Point Error Checks (Advanced Optimization) Disables Visual Basic floating-point error checking.
Remove Integer Overflow Checks (Advanced Optimization) Disables Visual Basic integer overflow checking.
Remove Safe Pentium(tm) FDIV Checks (Advanced Optimization) Disables checking for safe Pentium(tm) processor floating-point division.

For More Information   For more about native code options, see "Native Code Compiler Switches."