@5sw,
OOP is really about the following things:
- encapsulation
- extensibility via inheritance
Both of these can have significant impacts on your performance.
Here's a way to think about it, using a Vector2f as an example.
The "object" approach":
1
2
3
4
5
6
7
8
9
10
11
12
13 | class Vector2f {
private:
float x;
float y;
public:
float get_x() const { return this->x; }
float get_y() const { return this->y; }
void set_x(float nx) { this->x = nx; }
void set_y(float ny) { this->y = ny; }
virtual float length() const { ... }
};
|
The "non-object" approach:
| typedef struct {
float x;
float y;
} Vector2f;
|
Here's the thing, as a consumer of the Vector2f type, you have no guarantees of what the memory layout of the type is going to be; that's a key tenant about OO. The logic around that is encapsulated from you. I could go add a few other properties at a later time to cache values like the dot product, normal values, etc... and add that to the class and you won't know that.
For high-performance code, this is a really bad thing, especially if you are using a library that is providing these types because they can and do change over time. You can literally go from build to build of your product with different performance characteristics just because someone is mucking with the "private" portion of the Vector2f class.