Re: About virtual and abstract method

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"David Zha0" <zhplive@xxxxxxx> wrote in message
news:OCwHpFQfHHA.4596@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

"when we call a virtual method, the runtime will check the instance who
called the method and then choose the suitable override method, this may
causes the performance drop down", is this right?

Yes, because the exact behavior of the call can be different for each
object. Although the JIT compiler may be able to inline virtual calls
anyway for the most common cases. This is really only a concern for short
methods, where the callvirt overhead is a large fraction of total execution
time.


And, why not use "new" instead of using "virtual"?

New creates a new method slot, so you don't override the existing method.
That is to say, that a call made through a base class (or interface)-typed
variable won't call your version.


And the last question, what is the differences between a abstract method
and
a interface?

An abstract method can exist in a class alongside non-abstract methods. For
instance:

abstract class Checksum32Computer
{
public abstract bool Calc(byte[] array, int offset, int length, out int
checksum);
public bool Calc(byte[] array, out int checksum) { return Calc(array, 0,
array.Length, out checksum); }
}

But you only get single inheritance of abstract classes.


.



Relevant Pages

  • Inserting IPv4 header checksum into dummy IP header
    ... The checksum value is calculated using the algorithm used ... checksum value into the IP header. ... int main ... The first byte of this chunk is the continuation ...
    (comp.lang.c)
  • Inserting IPv4 header checksum into dummy IP header
    ... The checksum value is calculated using the algorithm used ... checksum value into the IP header. ... int main ... The first byte of this chunk is the continuation ...
    (microsoft.public.vc.language)
  • Re: Translating c code help required
    ... Checksum = checksum + Chr) ... unsigned int ... mag_checksum(const char * const buf) ... int csum = 0; ...
    (comp.lang.c)
  • Re: Translating c code help required
    ... I am trying to find out how the checksum is computed for a Megellan ... unsigned int ... mag_checksum(const char * const buf) ... int csum = 0; ...
    (comp.lang.c)
  • [PATCH] add checksum selftest
    ... Start a checksum internal testsuite for arch porters and people mucking ... -static unsigned int do_csum(const unsigned char *buff, ...
    (Linux-Kernel)