Version

menu_open
Warning : Some protected information on this page is not displayed.
Ensure you are logged in if you are a licensed user for specific platforms.
Wwise SDK 2024.1.0
Memory Manager

All modules of the Wwise sound engine access memory through the AK::MemoryMgr interface. The client of the sound engine is responsible for initializing and terminating this interface.

A default implementation is provided with the SDK as a static library (AkMemoryMgr.lib). To use this library, the client needs to include the AkModule.h header, and call the AK::MemoryMgr::Init initialization function.

Refer to Build Configuration for more information regarding the usage of AkMemoryMgr.lib and other libraries.

Initialization

In the default implementation, default initialization settings can be obtained using AK::MemoryMgr::GetDefaultSettings.

Using the Default Memory Allocator

By default, all memory is allocated by Wwise using the built-in AkMemoryArenas, each of which can be configured separately using the AkMemSettings::memoryArenaSettings array. There are up to four AkMemoryArenas that can be configured:

  • AkMemoryMgrArena_Primary: The default AkMemoryArena used by most memory categories.
  • AkMemoryMgrArena_Media: The AkMemoryArena used for memory allocations that go to the Media memory category, usually from loading SoundBanks.
  • AkMemoryMgrArena_Profiler: The AkMemoryArena used for memory allocations that go to the Profiler and Monitor Queue memory categories. This AkMemoryArena does not exist in the Release build configuration.
  • AkMemoryMgrArena_Device: The AkMemoryArena used for handling any device-specific memory allocations. This is present only on specific platforms that use device-specific memory for audio processing, that is, any platform that has AK_DEVICE_MEMORY_SUPPORTED defined.

We recommend you implement the following callbacks for each of the AkMemoryArenas, for integration into a game engine, as they are used by the AkMemoryArena to acquire and release spans of memory as needed.

  • AkMemoryArenaSettings::fnMemAllocSpan
  • AkMemoryArenaSettings::fnMemFreeSpan

AkMemoryArenaSettings::uMemReservedLimit is also available to set limits on how much memory is reserved by each AkMemoryArena.

Refer to Configuration and Tuning of AkMemoryArenas for information on other settings available for configuring the AkMemoryArena.

Using a Custom Memory Allocator

To override the use of AkMemoryArena and use a custom allocator for every memory allocation, provide overrides of all of these callbacks:

It is important for the allocation functions above to honor the AkMemType_Device bit by returning device memory when the bit is set.

Note: Profiling of AkMemoryArenas in Wwise is not available when using a custom memory allocator.

Configuration for Debugging

Use the following setting to enable additional runtime debugging functionality:

This is an opaque value to allow custom implementations to define as many memory debugging features as they like. The default implementation provides two levels.

  • Level 1 enables basic runtime memory debugging including; capturing FILE and LINE for each allocation, tracking callstacks ( where possible ) for each allocation, reporting leaks in a detailed manner upon shutdown and some very light integrity checks. This is light enough that you may run this during development by default.
  • Level 2 enables the use of a stomp allocator which uses discrete pages of virtual memory for every allocation and seeks to trap any writes that occur out of bounds. This is a very slow and resource hungry mode and as such we do not recommend you enable it by default during development but instead when you are trying to track the cause of a memory stomp only.

Use the following to dump all allocations to a file (note that this requires AkMemSettings::uMemoryDebugLevel to be 1 and a non Release configuration):

Remark: The sound engine opens a stream for writing using AK::IAkStreamMgr::CreateStd(). If you are using the default implementation of the Stream Manager, file opening is executed in your implementation of the Low-Level IO interface AK::StreamMgr::IAkLowLevelIOHook::BatchOpen().

Use the following settings to perform tracking of allocations for debugging purposes (these are not called in the Release configuration):

The debug functions above do not replace the allocation functions; they are notification callbacks for the various memory allocation events.

For more information, refer to the following sections:

  • Samples for sample code and more information regarding the initialization of the Memory Manager in your game.
  • Loading Banks for more information regarding SoundBank memory usage.
  • Optimizing Memory Utilization for information about optimizing memory utilization.

Overriding the memory manager

It is possible for a client to provide a custom implementation of the AK::MemoryMgr interface. All functions defined in AkMemoryMgr.h should be implemented. The functions from the AK::MemoryMgr namespace defined in AkModule.h do not need to be implemented as they are specific to the default implementation of the memory manager.

As when overriding the various allocation functions of AkMemSettings, when writing a new AK::MemoryMgr implementation care must be taken to honor the AkMemType_Device bit by returning device memory when the bit is set. Device memory allocation is used on certain platforms only, and must conform to specific parameters: refer to the platform-specific section for details.


Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise