I've written my own DirectSound8 implementation and load most of the sounds at game start into memory. As music in wav format can get quite big (20-30MB per file) I only load it when required during gameplay and free it after it has been played.
Even on my rather fast PC this leads to some stutter (loading from my custom container file from the hard disk, then CreateSoundBuffer and QueryInterface (which creates the final buffer)), which will be much worse on lower end machines.

Therefore - as DirectSound seems to be multithreading safe -, I both load the file in a separate thread (using fopen/... instructions and sys_malloc) and create the soundbuffer as well.
This seems to be working fine, however I want to make sure it's actually thread safe.

I assume sys_malloc(size) is just something like malloc(size+8) during development, which writes the sys_marker in the first 3 bytes and some security byte at 3(4) and after size.
When I google thread safety of malloc I get a bunch of "it depends" answers, such as here: https://stackoverflow.com/questions/855763/is-malloc-thread-safe
Are (sys_)malloc and free thread safe in acknex/ lite-C?
Using the forum search I've found that add_buffer seems to be thread safe, which probably does at least one malloc itself as well but I want to be sure.
Thanks.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends