The Visual Basic Compiler’
Visual Basic applications can be executed in two.mo~es: as p-code (from within the Visual Basiq JOE) and as natil’f code (when compiled to EXE files): Prior to version 5, VisualBasic could only ‘produce p-code. Where native code is understood directly by the processor arid executed as is, code is a special’ form of executable that must first be translated into native and then executed. Even with Visual· Basic 6, when you run a project in the IDE, you’re actually running p-code. Any project will run faster (marginally or .signific~tly faster, depending on the nature of the · calculations it performs) when it’s compiled to native code and executed outside the Visual Basic IDE, Tounderstand why native code performs better than p-code, you must first understand the nature of p-code and low Visual Basic.
. . . .
When you design and test an application, you’ll be executing it from within the IDE. When you’re done and ready to distribute.the application or use it on a daily basis yourself, you should compile it to native code. Dependingon the nature Of the application, the compilation may speed it up considerably or not at all. If the compiled application doesn’t run faster and its size is considerably larger than the size of the equivalent p-code executable, this may lead to longer loading times. In these instances/ pumay deCide to use the p-code executable.
What Is P-Code ?
The text you enter in the Visual Basic editor is translated into p-code as you enter it. Each time you press-Enter tomove to the next line, the IDE translates the line you’re leaving into p-code.All the syntax checking and color coding of the statements takes place after the line is translated into p-code, which explains why the · current line isn’t colored as you type.
To run p-code, VISualBasic uses a so-called execution engine: a DLL (Dynamic Link Library) that translates p-code into machine-executable code, or native code. This is how projects are executed in the-VISualBasic IDE. To distribute the application, you can create an executable file that contains the p-code plus the execution engine. The EXE files produced by previous versions of VISUalBasic were nothing more than p-code and the runtime DLL That’s why running an executable file out-, side the IDE wasn’t any faSter than running the application in it.
• The VISualBasic 6 native code,compiler is similar to a traditional compiler, such as the one used by VJSUalc++. It produces processor-specific instructions that can be .:. executed directly without any additional translation. Thus, it’s easy to understand why native code executes faster than p-code. In reality, VISUalBasic’s p-code is so highly optimized that you might not get a great improvement in speed in native code over p-code. (It seems that Miaosoft couldn’t improve p-code any further, and the introduction Qfa native code compiler was inevitable.) Another reason native code outperforms p-code is that it can do glcbal optimizations. is generated on thefly and executed one line at a time. By contrast, the native code compiler can see the big picture (many lines of source code at once) and produce optimal executable code that takes into consideration the peculiarities of and dependencies among multiple lines of code.