Author Topic: Object Oriented Programming performance  (Read 1251 times)

0 Members and 1 Guest are viewing this topic.

Offline Mika

  • 28
Object Oriented Programming performance
Just Great

I just figured that the whole stuff I have recently done is actually Object Oriented Programming, but the whole thing is in C & MEX (C89, to be accurate, and MEX is a cross of MATLAB and C, mainly C but sporting some cute functions from MATLAB and retaining full MATLAB functionality). I wrote the whole thing as a library of functions that is interacted with integer numbers which tell the library what it is supposed to do, if supplemented with necessary information - which would be arrays and arrays of doubles - from the requester's side. Currently it works pretty nicely, and is sufficiently fast. As before, computational speed is crucial in all of my cases. For those wondering, the question is about ray-tracing.

I have never had any C++ Object Oriented programming course, neither do I know what those fancy Class and Template thingies are. But my question for C++ programmers here would be that how much of a performance penalty can I expect using those fancy Classes and Templates to do the same thing? I'm pretty sure there is some overhead involved, since now I can do the whole thing with integer numbers.

Mika
Relaxed movement is always more effective than forced movement.

 

Offline Flipside

  • əp!sd!l£
  • 212
Re: Object Oriented Programming performance
To be honest, it's more a question of how you code in my experience.

Classes are useful if you work a lot with 'packets' of information, they can be self-contained, which helps with things like threading etc.

As far as my awareness goes, if you want to go multi-threaded in the future, then Class-based code is a lot easier to do this with than big Monolithic lumps of code. Other than that, I'm not certain of any real performance hit purely for using the style itself, simply that bad coding can cause a bigger performance hit than it would if you were working with Procedures etc.

 

Offline phreak

  • Gun Phreak
  • 211
  • -1
Re: Object Oriented Programming performance
Templates cause the compiler to compile separate classes for each type used.  For example, a program needing vector<int> and vector<double> will cause the compiler to compile the vector<T> class twice, causing longer compilation times and larger executable size.

For classes, there shouldn't be any performance hits until you start using polymorphism, and even then the VTBL lookup is a pointer dereference, so it's nothing substantial.
Offically approved by Ebola Virus Man :wtf:
phreakscp - gtalk

 

Offline Mika

  • 28
Re: Object Oriented Programming performance
Thanks for replies,

I thought that even class definitions would cause a performance hit, but I'm not sure any more. The logic went somehow that if it is not inside a single function (or a single file), then there will be inevitably some overhead by switching from function to function. It is possible I misunderstood something of those things when I started reading about them.

Mika
Relaxed movement is always more effective than forced movement.