C++ function objects have overhead? This is news to me... Any decent compiler can optimize these as well as a direct function call. Also because of the way that the code is generated using templates (as in machine language isn't generated until the actual call is reached), function bodies are visible to the compiler at compile time a larger percentage of the time which allows for better optimization. Ofcourse there are ways to break this rule, but it is like anything in C++, if you don't know how to use it for speed, you can get yourself into trouble. Also, the alternative is usually function pointers which have atleast 50 times the overhead of a function object. Correct me if I'm wrong.
- Nick On 2/15/07, Jason House <[EMAIL PROTECTED]> wrote:
Heikki Levanto wrote: > To get down to earth, I would like to look at the board at the end of > each playout, calculate something more than just win/loss, and pass that > info back to who ever called playout. One way to do that would be to > pass a function pointer and a (void?) pointer to playout, and have it > call back the function with the board, winner, and the void pointer. If > that sounds more like C than C++, it is because I am a C programmer. If > some other C++ idiom could do the same thing, all the better. > If you're going for more of a C++ library feel, function objects are the way to go. Function objects impose extra overhead but add a potential for a more generic adapter around other code that uses it. I have yet to convince myself of the benefit of C++ function objects for most applications. C++'s support for them is just too clunky in comparison to other C++ language features (or equivalent ones in other languages with built-in support). _______________________________________________ computer-go mailing list computer-go@computer-go.org http://www.computer-go.org/mailman/listinfo/computer-go/
_______________________________________________ computer-go mailing list computer-go@computer-go.org http://www.computer-go.org/mailman/listinfo/computer-go/