XNA Content.Load如何实现操作?
我只是好奇它是否在每次调用时实际上将资源加载到内存中,或者如果它查找它,发现它是否已加载,如果未加载,则加载一次并仅保留引用,以便第二次调用它只是获取对它的引用?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它跟踪已经加载的内容,并且如果之前已经加载过,则简单地返回对同一对象的引用(这是每个 ContentManager)。这适用于所有内容,而不仅仅是纹理。
结果是,只要您需要一些内容,您就可以调用
Load
,而不必考虑重复。另一个结果是,您永远不应该Dispose
从 ContentManager 加载的内容(使用ContentManager.Unload
代替)。如果您想了解更多详细信息,查看此问题并回答。
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 neverDispose
of content loaded from ContentManager (useContentManager.Unload
instead).If you want more detail, take a look at this question and answer.