Candy wrote:
Ready4Dis wrote:
That was a perfect example of what not to do in the kernel... virtual functions. Granted, some people really don't care about performance, if that's the case, go for whatever is easier then, just don't expect miracles when you start benchmarking your kernel against others
. You do realize you could just as easily store a pointer to your current putChar right?
*that's exactly what virtual functions ARE*.
Quote:
I am more from the performance side of the house...
Try using a profiler next time. Or code analysis.
I've done both, and I can say for 100% certainty (after a good amount of benchmarking thank you) that having a class full of virtual functions vs. a single device pointer is much slower. Yes, virtual functions ARE pointers, congratulations, you made it past C++ 101... Anyways, I'm not going to argue, just re-iterate what I've said. If you don't care about performance, and just want code readability (which he clearly stated he preferred), then go for it. The overhead of virtual functions, especially in higher level functionality is minimal, it's when people start abusing it in inner loops that require speed that the difference really shines. If the person knows how to use it, and when to use it, you can minimize the performance hits, which I and others have already stated. If you bothered to read his code, instead of just try to jump down my throat about how a virtual function is a pointer, you'd realize how inefficient his IOOutputStream class is. Firstly, in order to support multiple devices, he'd still need an array, or list of output streams... there's MY device pointer reference. Now, EACH of those streams has a set of virtual functions, which has an extra memory lookup to perform. If he calls printf, then calls putChar... that's another extra lookup. Yes, for an iostream, who cares, I'm sure it'll print to the screen plenty fast enough, but in general (unless you are VERY careful) virtual functions end up adding extra code, and slowing things down (how badly, and how much the effect depends on what ti's being used for).