[computer-go] Drunken sailor on payday

Nick Apperson apperson at gmail.com
Wed Nov 21 10:30:19 PST 2007


sure thing:

----------------------------------------------

struct foo {
  // some stuff gets executed
  virtual void do_something(somestruct &s); // base case executed by default
};

struct foo_foo : foo {
  // some stuff gets executed
};

struct foo_bar : foo {
  // some stuff gets executed
  virtual void do_something(somestruct &s); // special case
};

So then if we have say:

foo *f;
somestruct s;

// ... some code that sets f to something and changes s

f->do_something(s);

----------------------------------------

So now when the compiler is optimizing the code, it will optimize for the
base case of foo::do_something by default unless it has information that is
even better.  If our code instead read with f as a function pointer, the
compiler (assuming it can't determine the value) won't have a base case.


On Nov 22, 2007 12:18 PM, Petr Baudis <pasky at ucw.cz> wrote:

> On Thu, Nov 22, 2007 at 12:04:53PM +1800, Nick Apperson wrote:
> > right... well C++ does have this using virtual methods.  I meant to add
> that
> > part.
>
> I'm sorry, I still don't get this - what do virtual methods have to do
> with branch prediction? Can you elaborate, please?
>
> --
>                                Petr "Pasky" Baudis
> We don't know who it was that discovered water, but we're pretty sure
> that it wasn't a fish.          -- Marshall McLuhan
> _______________________________________________
> computer-go mailing list
> computer-go at computer-go.org
> http://www.computer-go.org/mailman/listinfo/computer-go/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://computer-go.org/pipermail/computer-go/attachments/20071121/67425d5e/attachment.htm


More information about the computer-go mailing list