• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Using local variables for external audio- is this efficient?

L

LV154

Guest
As far as I'm aware using external sounds leads to better performance. Therefore my project so far relies
exclusively on loading external sound.
The project uses around 150 so far so assigning an instance variable to every sound seems a little silly.
Therefore much of the sound code looks something like this:
Code:
var sound;
sound=sound_add(working_directory+"sound.wav",0,0)

sound_play(sound)
Because local variables are forgotten straight after the event is over, is the sound automatically deleted or does it cause a memory leak as sound keeps getting added? I'm not quite sure how Gamemaker 8 handles sound and whether I should be worried about this
 

jo-thijs

Member
Hi and welcome to the GMC!

It causes a memory leak.
You have to use sound_delete to prevent the memory leak.
But you shouldn't load sounds to often either, as that could cause noticeable lag.
Having them as instance or global variables sounds like a better idea to me.
 
L

LV154

Guest
Hi and welcome to the GMC!


But you shouldn't load sounds to often either, as that could cause noticeable lag.
Having them as instance or global variables sounds like a better idea to me.

Thanks for the quick reply! I was wondering then, is there any real advantage to external sound if you can just load them into gamemaker and untick the preload option? Seems to me that this takes away the need to constantly load and delete sound while conserving memory. I might be wrong though.
 
L

LV154

Guest
This, I don't know.
Why did you originally think it was better to load sounds externally?
I thought this is a better way of handling memory. I assumed loading sounds into game maker means the executable will take more memory as a whole. Perhaps ticking the preload option makes a difference but again, I'm clueless on how game maker 8 handles sound despite reading the documentation.
 

Llama_Code

Member
One benefit to external sounds is your exe is smaller and loads faster. 150 sounds, especially if large, would cause a significant hit to your loading time.

However I don't know if having them included would raise the memory footprint, wouldn't be to hard to test it though.
 
Top