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\$

1 Answer 1

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\$
1
  • \$\begingroup\$ You are right! I did not read thoroughly.. \$\endgroup\$
    – markmnl
    Commented Jan 23, 2012 at 0:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .