Jean
Jean

Reputation: 731

Does OO programming conflict for latency applications?

I just wondered whether OO programming can cause problems for those who design latency applications? Do those who write latency code use OO programming? It'd be interesting to know if the extendability of OO programming trades against the speed of the code?

For instance, I read that virtual functions in C++ are a big 'no no' for latency programmers?

Upvotes: 1

Views: 72

Answers (2)

Marc Gravell
Marc Gravell

Reputation: 1063198

The vast majority of code is not CPU bound. CPUs are ridiculously fast, and spend most of their time waiting passively for IO to catch up. So in most sane cases I would say "no".

It is possible that you have an application that does everything in memory, has perfect loop structures etc, and in this mythical beast you might eek out a tiny bit more performance by forsaking virtual functions. But that is a pretty extreme scenario.

It will depend on the context basically. Generally this is simply not an issue; java / c# are themselves pretty well optimised (on the desktop/server versions at least) and are not massively slow.

Upvotes: 2

Puppy
Puppy

Reputation: 146970

No. Compared to other costs like memory locality and cache coherence, algorithm design and language base (interpreter, vm, native), a few virtual functions are a quite trivial cost. OO principles like encapsulation are wholly compile-time operations, and abstraction can be achieved for free using generic programming. Unless you go totally overboard with them, which in some cases is quite unavoidable in languages which simply don't have generic programming, or if you're calling it in an incredibly tight loop, but in that case you likely won't find a cheap alternative.

Whoever told you that programmers who are concerned with performance in C++ do not use virtual functions was wrong.

Upvotes: 1

Related Questions