


Is there a WinAPI function I can call to defrag my app's memory? I'm not too familiar with underlying windows memory management, but it seems that there is memory defrag operation that works in the background, otherwise the memory allocation issues would be constant and not random (working, not working and working again in the span of a second).

That is, until my GDI+ based JPEG decoding code started exhibiting random memory allocation issues. It seemed like an elegant solution, just fire and forget, windows took care of the sound mixing and it worked reasonably well. I thought the smartest/cleanest way would be to create a new thread for each SFX, play it using DirectShow and then let the thread clean itself up. I needed to write a SoundFX playback module that supported multiple audio devices, volume level, and multiple effects playing. I'm using Delphi 7, 16GB ram, Windows 10.
