为纯虚函数所生成的代码如列表1 中所示。
The code generated for the pure virtual function is shown in Listing 1.
在头文件中为该虚函数所生成的代码如列表2中所示。
The code generated for the virtual function in a header file is shown in Listing 2.
当然,如果类层次结构发生变化,并且出现另外的目标方法,则JIT编译器可以更正最初生成的代码以便执行虚调用。
Of course, if the class hierarchy changes and a second target method becomes possible, then the JIT compiler can correct the originally generated code so that the virtual invocation is performed.
研究表明:大多数虚调用只有一个目标对应于所有的接收方对象,而JIT编译器可以为直接调用生成比虚调用更有效率的代码。
Research has shown that most virtual invocations have only a single target for all receiver objects, and JIT compilers can generate more-efficient code for a direct call than for a virtual invocation.
Rhino代码读起来很像C程序:它避免过多的分配,并且尽量多地使用跳转表(Jump Tables)来避免虚方法查询(Virtual Method Lookups)的额外开支。
The Rhino code base reads almost like C code: it avoids allocation and does as much as possible with jump tables to avoid the overhead of virtual method lookups.
如果函数是虚函数,并且调用是通过引用或者指针,编译器基于动态类型生成代码确定调用哪个版本。
If the function is virtual and the call is through a reference or pointer, then the compiler generates code to determine which version to run based on the dynamic type of the object.
另外,硬件虚存机制可以对内存部分区域提供写保护,以防止代码和数据被其它恶意的应用程序所篡改。
Also, the hardware virtual memory mechanisms allow areas of memory to be protected against writing. This protects code and data from being overwritten by rogue applications.
所谓虚类或虚函数是指应用程序以后需要,但是目前还没写的代码。
A virtual class or function is code that the application will eventually need, but it isn't written yet.
所谓虚类或虚函数是指应用程序以后需要,但是目前还没写的代码。
A virtual class or function is code that the application will eventually need, but it isn't written yet.
应用推荐