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.
<
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) {
}
}
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();
:
:
:
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