Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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 obviously be very slow :-/

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.