How does XNAs Content.Load<Texture2D> operate?

Deadly 提交于 2019-12-11 03:43:47

问题


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 and 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?


回答1:


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.



来源:https://stackoverflow.com/questions/4242741/how-does-xnas-content-loadtexture2d-operate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!