XNA Content.Load如何实现操作?

发布于 2024-10-03 07:58:02 字数 88 浏览 1 评论 0原文

我只是好奇它是否在每次调用时实际上将资源加载到内存中,或者如果它查找它,发现它是否已加载,如果未加载,则加载一次并仅保留引用,以便第二次调用它只是获取对它的引用?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆里有你的影子 2024-10-10 07:58:02

它跟踪已经加载的内容,并且如果之前已经加载过,则简单地返回对同一对象的引用(这是每个 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 never Dispose of content loaded from ContentManager (use ContentManager.Unload instead).

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文