views:

64

answers:

3

In XNA, when calling Content.Load() to load in a resource, if you load the same resource into multiple objects (i.e. the texture for a projectile of which there can be many) are you getting a copy for each object, or is the system just internally referencing the same memory for each one?

I was realizing that having a separate Texture2D object in each item may be a memory issue down the line.

+4  A: 

The ContentManager will cache the object and return the reference to that object when you try to load it again.

Marcus
So, if I load into a Texture2D in 2 different objects and then modify the texture data in one, does it get changed for both of them?
Adam Haile
+2  A: 

Yes modifying the texture data will change all textures that reference that data.

If you need multiple ones then duplicate the original file and load different versions.

Andy Dunn
hmm not an ideal solution ... no way to copy the object structures data in memory?
John Nicholas
+1  A: 

You would need to make a new Texture2D object and simply copy the changed data into the new texture with the SetData method:
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.texture2d.setdata.aspx

Joel Martinez