realbasic-nug
[Top] [All Lists]

Re: Events faster than virtual methods?

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Events faster than virtual methods?
From: Charles Yeomans <yeomans at desuetude dot com>
Date: Tue, 31 Aug 2004 18:28:23 -0400
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <p06002005bd5aa9327532 at [203 dot 23 dot 218 dot 140]>

On Aug 31, 2004, at 6:21 PM, Andy Dent wrote:

Guyren G Howe wrote recently

I feel obliged herein to insert my occasional comment that, RB's docs notwithstanding, the preferred method of class extension in REALbasic is to use events, not method overriding.

I don't necessarily agree but it made me think about dispatching overhead.

Events on controls in windows are bound at editing time (even earlier than compile-time) which is why the IDE knows to hide an event in the editor if it is handled in a parent class.

I infer that they are not dispatched through a virtual method lookup.

This implies, if you have a method you want called often enough for it to be important to optimise, that events would be better than methods (eg: something called per pixel, processing every frame of a movie or in a large image).

However, thinking about it, I'm not sure there's enough context for early binding to occur in events used outside of windows.

Maybe outside a window, event calls are straight virtual function calls.

Maybe they always are?


I've tested this out; there is no difference in execution speed as far as I can determine -- except in the case of unimplemented methods/events. Unimplemented methods are called, but unimplemented events are not. Your mileage may vary.

--------------
Charles Yeomans

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>