Does virtual memory get used when loading sound into memory? It appears that it doesn’t work that way. If it is true, why doesn’t virtual memory get used? Is it an FMOD, DirectX or OS issue? Could it be because virtual memory would be too slow.
For example :
The machine that I’m working on has 1GB of memory.
We tried to load a big file of about 340mb. It worked. We tried to load it again, and we get the "Not enough memory or resources." error because we don’t have enough physical memory left but plenty of virtual memory.
- Steph asked 10 years ago
A 340MB audio file is not guaranteed to use 340MB of memory. Address space fragmentation from repeated allocs/frees will clutter your available address space, reducing the amount of memory you can allocate in one large chunk within your process without visibly reducing your free memory. Additionally, depending on the way you’re loading the audio it could use more than 340MB of space when fully loaded (for example, if you load an 8bit 22khz wav file the audio library might convert it to 16-bit for more efficient playback/mixing. this would double the amount of memory it uses.) Also, on Win32 most applications are only able to allocate a total of 2GB of memory, or depending on your configuration 3GB – about a gigabyte of your address space is always reserved for the kernel and another gigabyte is reserved for libraries (DLLs) – Some or all of FMod’s data and code may be occupying some of the DLL address space, further fragmenting the available space.
If you need to repeatedly load the same audio file as multiple sounds and are having problems with memory usage, you could try mapping the file into memory and using openmemory to create sounds from the mapped area, so that it doesn’t use as much additional memory.
If you need to regularly work with multiple large audio files at once using FMod, I would suggest implementing a system to allocate and deallocate the sounds on demand and use memory mapping to load the sounds into memory and use openmemory to create FMod sound handles for playback without having to perform a full load. You’d probably have to repeatedly map and unmap sounds to free up needed address space but since it won’t actually be necessary to read in all the audio data the performance should be acceptable. (For realtime audio playback, of course, using fmod’s streaming would probably be more ideal. But if you’re after realtime scrubbing and scanning through the audio this is probably the way to go.)
- Janus answered 10 years ago
Please login first to submit.