开发者

Does SoundEffect.CreateInstance load from file everytime?

This is something which has been bugging me. If I create a SoundEffectInstance via SoundEffect.CreateInstance() I'm meant to dispose of it when I'm finished with it. SoundEffect.CreateInstance() does not use ContentManager as far as i can tell.

So does it load from file or does it keep a copy in memory? Loading from file would obvi开发者_StackOverflow中文版ously be very slow :-/


It's an implementation detail. You don't know for sure, it doesn't matter, it might differ between platforms, and it might change in the future.

However you can make an educated guess: First of all the fact that SoundEffectInstance exists, and that you load sound files into SoundEffect indicates that SoundEffect is probably responsible for holding the sound effect in memory. And the existence of SoundEffect.FromStream and the buffer-based SoundEffect constructors are strong indications that SoundEffect must have a mechanism for keeping a sound buffer in memory. Therefore it is fairly safe to assume that when you load a SoundEffect from a file, it uses the same mechanism.

If it's really important, you could test it by deleting or modifying the sound file, after loading the SoundEffect, and then creating an instance.

As always, if performance is really important, you should measure it.

Of course, creating a SoundEffectInstance does allocate resources (audio voices, managed and probably unmanaged memory). So it's not something that you should be creating regularly if you can avoid it - such as by pooling and reusing instances. When you're using SoundEffect.Play, then SoundEffect is internally managing a pool of SoundEffectInstance objects for you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜