Pitfalls of Object Oriented Programming

Topics: Object-oriented programming, CPU cache, Cache Pages: 33 (2189 words) Published: November 1, 2010
Sony Computer Entertainment Europe Research & Development Division

Pitfalls of Object Oriented Programming
Tony Albrecht – Technical Consultant Developer Services

What I will be covering

• A quick look at Object Oriented (OO) programming • A common example • Optimisation of that example • Summary Slide 2

Object Oriented (OO) Programming
• What is OO programming?
– a programming paradigm that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. (Wikipedia)

Includes features such as
– – – – Data abstraction Encapsulation Polymorphism Inheritance

Slide 3

What’s OOP for? • OO programming allows you to think about problems in terms of objects and their interactions. • Each object is (ideally) self contained – Contains its own code and data. – Defines an interface to its code and data.

• Each object can be perceived as a „black box‟.
Slide 4

Objects • If objects are self contained then they can be
– Reused. – Maintained without side effects. – Used without understanding internal implementation/representation.

• This is good, yes?
Slide 5

Are Objects Good? • Well, yes • And no. • First some history.

Slide 6

A Brief History of C++

C++ development started



Slide 7

A Brief History of C++

Named “C++”

1979 1983


Slide 8

A Brief History of C++

First Commercial release




Slide 9

A Brief History of C++

Release of v2.0




Slide 10

A Brief History of C++
Added • multiple inheritance, • abstract classes, • static member functions, Release of v2.0 • const member functions • protected members.




Slide 11

A Brief History of C++





Slide 12

A Brief History of C++





Slide 13

A Brief History of C++





Slide 14

So what has changed since 1979?
• Many more features have been added to C++ • CPUs have become much faster. • Transition to multiple cores • Memory has become faster. http://www.vintagecomputing.com

Slide 15

CPU performance

Slide 16

Computer architecture: a quantitative approach By John L. Hennessy, David A. Patterson, Andrea C. Arpaci-Dusseau

CPU/Memory performance

Slide 17

Computer architecture: a quantitative approach By John L. Hennessy, David A. Patterson, Andrea C. Arpaci-Dusseau

What has changed since 1979? • One of the biggest changes is that memory access speeds are far slower (relatively) – 1980: RAM latency ~ 1 cycle – 2009: RAM latency ~ 400+ cycles

• What can you do in 400 cycles?
Slide 18

What has this to do with OO?

• OO classes encapsulate code and data. • So, an instantiated object will generally contain all data associated with it.

Slide 19

My Claim

• With modern HW (particularly consoles), excessive encapsulation is BAD. • Data flow should be fundamental to your design (Data Oriented Design) Slide 20

Consider a simple OO Scene Tree

• • •

Base Object class
– Contains general data

– Container class

– Updates transforms

– Renders objects

Slide 21


• Each object
– – – – Maintains bounding sphere for culling Has transform (local and world) Dirty flag (optimisation) Pointer to Parent

Slide 22

Class Definition Each square is 4 bytes
Memory Layout

Slide 23


• Each Node is an object, plus
– Has a container of other objects – Has a visibility flag.

Slide 24

Class Definition
Memory Layout

Slide 25

Consider the following code…

• Update the world transform and world space bounding sphere for each object.

Slide 26

Consider the following code…

• Leaf nodes (objects) return transformed bounding spheres

Slide 27

Consider the following code…

Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Object Oriented Programming Essay
  • Object Oriented Programming Essay
  • Reusability: Object Oriented Programming Essay
  • Essay about Introduction to Object Oriented Programming
  • Comparison of Object Oriented and Structured Programming Essay
  • Object-oriented Programming and Systems Analysis Essay
  • Object-oriented Programming and Java Statement Essay
  • Introduction to Object Oriented Programming Concepts Essay

Become a StudyMode Member

Sign Up - It's Free