Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm fairly new to programming, and I've pretty much learned all the things I know on the go, while working on projects. The problem is that there some things that I just don't know where to begin searching.

My question is about performance, and how can multiple instances of the same object affect it -- Specifically, I'm talking about XNA's "GraphicsDevice" class. I have it instanced on four different parts of my game, and in three of those, the object has the exact same values for all the attributes. So, in that case, should I be using the same instance of GraphicsDevice, passing it as a parameter, even if I use it in different classes?

I apologize if the question seems redundant, but like I said, I've taught myself most of what I know, so there are quite a few "holes" in my learning process.

share|improve this question
1  
For your reference and just to be clear, "objects" are instances of a class. You don't have "instances of objects." You may have a reference to the same object in memory, but otherwise, "objects" are instances of a class (in your case GraphicsDevices). You may want to clarify if those "other instances of the same object" are really references to the same object or are separate objects. Do you call new GraphicsDevice(...) anywhere? –  Richard Marskell - Drackir Jul 23 '12 at 18:39
    
To clarify terminology: classes are types, objects/instances are variables. –  David Lively Aug 22 '12 at 20:18

1 Answer 1

Yes, you should have only one GraphicsDevice per game, and don't instance it manually ever. Just pass it as a parameter to the functions that need to access it or share it via a global singleton class.

share|improve this answer
    
Thank you for the reply! In your answer, you said that I shouldn't "manually instance" it. What do you mean by that? –  lggmonclar Jun 23 '12 at 18:39
2  
He means never call new GraphicsDevice(). This line should not appear in your code. XNA handles this for you and provides you with the only GraphicsDevice instance you will need. –  A-Type Jun 25 '12 at 17:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.