CRI ADX  Last Updated: 2024-07-17 10:47 p
Memory Usage


Memory to Use

The CRI Atom library does not perform dynamic memory allocation (memory allocation for the system by using the malloc function and so on) in the library.
The memory area and its size used by the CRI Atom library must be specified mainly at the initialization and when a function is called to create a handle.
For details, see 'About Working Memory .'


Calculation Method

In general, the memory size can be calculated by setting various Config structures and calling various CalculateWorkSize functions.
For processing that reads a file, the file size also affects the memory size.
The following table shows various types of processing that require a working Memory and working memory size calculation functions.


<

Various Types of Processing that Require a Working Memory and Working Memory Size Calculation Functions
Processing Details Processing Function Working Memory Calculation Function
Library initialization criAtomEx_Initialize criAtomEx_CalculateWorkSize
Streaming buffer creation criAtomExDbas_Create criAtomExDbas_CalculateWorkSize
Voice pool creation criAtomExVoicePool_AllocateStandardVoicePool criAtomExVoicePool_CalculateWorkSizeForStandardVoicePool
  criAtomExVoicePool_AllocateAdxVoicePool criAtomExVoicePool_CalculateWorkSizeForAdxVoicePool
  criAtomExVoicePool_AllocateHcaVoicePool criAtomExVoicePool_CalculateWorkSizeForHcaVoicePool
  criAtomExVoicePool_AllocateHcaMxVoicePool criAtomExVoicePool_CalculateWorkSizeForHcaMxVoicePool
ACF file loading criAtomEx_RegisterAcfData criAtomEx_CalculateWorkSizeForRegisterAcfData
  criAtomEx_RegisterAcfFile criAtomEx_CalculateWorkSizeForRegisterAcfFile
ACB file loading criAtomExAcb_LoadAcbData criAtomExAcb_CalculateWorkSizeForLoadAcbData
  criAtomExAcb_LoadAcbFile criAtomExAcb_CalculateWorkSizeForLoadAcbFile
AtomEx player creation criAtomExPlayer_Create criAtomExPlayer_CalculateWorkSize


Also, by using the User Allocator method and registering the functions as shown below, the memory size currently used can be obtained.


static CriUint32 usermem_allocated_size = 0;
void userMem_Initialize(void)
{
usermem_allocated_size = 0;
}
void userMem_Finalize(void)
{
if (usermem_allocated_size != 0) {
/* Error */
}
}
CriUint32 userMem_GetAllocatedMemorySize(void)
{
return usermem_allocated_size;
}
void *userMem_Alloc(void *obj, CriUint32 size)
{
void* mem = malloc(size + sizeof(CriUint32));
void* ptr = CRI_NULL;
if (mem != CRI_NULL) {
usermem_allocated_size += size;
ptr = (void*)((CriUintPtr)mem + sizeof(CriUint32));
*(CriUint32*)mem = size;
}
return ptr;
}
void userMem_Free(void *obj, void *buf)
{
Uint32 size;
void* mem;
if (buf != NULL) {
mem = (void*)((CriUintPtr)buf - sizeof(CriUint32));
size = *(CriUint32*)mem;
usermem_allocated_size -= size;
free(mem);
}
}
main()
{
userMem_Initialize();
// Register the own memory allocator function
criAtomEx_SetUserAllocator(userMem_Alloc, userMem_Free, NULL);
// Initialize the library
// Specify NULL and 0 as working memory
// -> Required memory is allocated using the registered memory allocation function.
criAtomEx_Initialize(NULL, NULL, 0);
:
// Application's main routine
:
// Finalize the library when exiting the application
// -> The memory allocated when initializing the library is released using the registered memory release function.
:
userMem_Finalize();
}
void criAtomEx_Finalize(void)
Finalize the library.
CriBool criAtomEx_Initialize(const CriAtomExConfig *config, void *work, CriSint32 work_size)
Initialize the library.
#define criAtomEx_SetUserAllocator(p_malloc_func, p_free_func, p_obj)
Register a custom memory allocator.
Definition: cri_le_atom_ex.h:309