Reputation: 916
I am making a game and I have noticed that keeping all the audio files in memory is generally not really memory efficient as longer (and therefor larger) audio files take up quite a lot of memory. I was wondering at which size the game should decide to stream the audio file, rather than storing it in memory?
Upvotes: 1
Views: 319
Reputation: 168845
..at which size the game should decide to stream the audio file, rather than storing it in memory?
I'd do it at OutOfMemoryError
. Anything before that is premature optimization.
Upvotes: 1
Reputation: 62120
You should not need to be concerned with this. Instead, try soft-referencing your resources.
See http://docs.oracle.com/javase/7/docs/api/java/lang/ref/SoftReference.html
Upvotes: 1
Reputation: 786
As a good practice, you should keep all audio(and texture) files in RAM. Reading audio files from ram is much faster than reading audio files from hard disk. It will make your game lagging if your game is designed to load an audio file and play it, when the audio is required, then destroy it when your game finish playing the audio.
The best way is do not load audio file when it isn't required.
For example, your game has 5 stages. In stage one, music_1.mp3 isn't required so you should not load it. Remove the audio files(audio for stage one only, which will not be used in other stage) from ram when stage one is finished.
Upvotes: 1