开发者

How does XNAs Content.Load<Texture2D> operate?

I'm just curious if it actually loads the asset into memory every time it's called or if it looks it up, finds if it's loaded a开发者_如何学编程nd if it isn't loaded it loads it once and just keeps references so the second time it's called it just grabs a reference to it?


It keeps track of what has already been loaded, and simply returns a reference to the same object if it has been loaded before (this is per-ContentManager). This applies to all content, not just textures.

The upshot is that you can just call Load whenever you need some Content, without having to think about duplication. The other upshot is that you should never Dispose of content loaded from ContentManager (use ContentManager.Unload instead).

If you want more detail, take a look at this question and answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜