3
\$\begingroup\$

Or is it smart enough to know I have asked for it before and return an in memory copy created from the first call?

For example if I have a projectile's texture:

Texture2D projectile;

If then I call:

projectile = ContentManager.Load<Texture2D>("bullet");

every time I want fire a new projectile - am I mallocing this on the heap or am I referencing the same copy in memory? If I am mallocing new memory each time I could keep it in memory myself by making the Texture2D variable static and not calling new each time one is fired! (I was just wondering about the ConentManger). The documentation (as with all the XNA documentation is skint on details: http://msdn.microsoft.com/en-us/library/bb197848.aspx).

\$\endgroup\$
7
\$\begingroup\$

In the same link you wrote, you'll find the following:

Return Value

The loaded asset. Repeated calls to load the same asset will return the same object instance.

However, normally, you'd keep it somewhere and only load it once, as it is faster to look at a global object than calling the ContentManager.Load method.

\$\endgroup\$
  • \$\begingroup\$ You are right! I did not read thoroughly.. \$\endgroup\$ – markmnl Jan 23 '12 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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