PrevNextUpHome SophiaFramework UNIVERSE 5.3

27.2. Function for Tracing Memory

Regarding all the memory operations in C++ language, the functions of tracing memory on the BREW Simulator are available.

27.2.1. MemoryAllocate Macro

The MemoryAllocate macro provides the memory allocation function with the capability of tracing memory on the BREW Simulator.

[Caution] Caution
The MemoryAllocate macro does not initialize the memory.

The MemoryAllocate macro is replaced with SFDWatcher::malloc when the TARGET_ENVIRONMENT_SIMULATOR macro is defined, and is replaced with SFXHelper::malloc when the TARGET_ENVIRONMENT_PHYSICAL macro is defined.

Example

SInt16Ptr p = reinterpret_cast<SInt16Ptr>(MemoryAllocate(sizeof(SInt16) * 256));
[Note] Note
The 256 memory blocks of SInt16 type are allocated in the above code.
[Caution] Caution
In SophiaFramework, the MemoryAllocate macro is used instead of the MALLOC and ERR_MALLOC BREW helper functions.

27.2.2. MemoryReallocate Macro

The MemoryReallocate macro provides the memory reallocation function with the capability of tracing memory on the BREW Simulator.

The MemoryReallocate macro is replaced with SFDWatcher::realloc when the TARGET_ENVIRONMENT_SIMULATOR macro is defined, and is replaced with SFXHelper::realloc when the TARGET_ENVIRONMENT_PHYSICAL macro is defined.

[Caution] Caution
The MemoryReallocate macro does not initialize the memory.

Example

SInt16Ptr p = reinterpret_cast<SInt16Ptr>(MemoryAllocate(sizeof(SInt16) * 256));
...
p = reinterpret_cast<SInt16Ptr>(MemoryReallocate(p, sizeof(SInt16) * 4096));
[Note] Note
In the above code, allocate the 256 memory blocks of SInt16 type, and then expand them to 4096 memory blocks of SInt16 type.
[Caution] Caution
In SophiaFramework, the MemoryReallocate macro is used instead of the REALLOC and ERR_REALLOC BREW helper functions.

27.2.3. MemoryFree Macro

The MemoryFree macro provides the memory free function with the capability of tracing memory on the BREW Simulator.

The MemoryFree macro is replaced with SFDWatcher::free when the TARGET_ENVIRONMENT_SIMULATOR macro is defined, and is replaced with SFXHelper::free when the TARGET_ENVIRONMENT_PHYSICAL macro is defined.

Example

SInt16Ptr p = reinterpret_cast<SInt16Ptr>(MemoryAllocate(sizeof(SInt16) * 256));
...
MemoryFree(p);
[Note] Note
The allocated memory area has been released.
[Caution] Caution
In SophiaFramework, the MemoryFree macro is used instead of the FREE BREW helper function.

27.2.4. The new/delete Operators

The functions called by the new / delete operator depends on the definition of the TARGET_ENVIRONMENT_SIMULATOR / TARGET_ENVIRONMENT_PHYSICAL macro regarding the validity of memory tracing function as the table below.

Table 27.2. Macro and called functions

Operator TARGET_ENVIRONMENT_SIMULATOR (valid memory tracing function) TARGET_ENVIRONMENT_PHYSICAL (invalid memory tracing function)
new SFDWatcher::malloc SFXHelper::malloc
delete SFDWatcher::free SFXHelper::free
[Caution] Caution
The new operator will not initialize the memory if initiation is not described in the constructor.

27.2.5. BREW Helper Functions Related with Memory

In SophiaFramework, the BREW helper functions for allocating and freeing memory can not be used.

Table 27.3. Macros, operators, functions, and classes substituting the BREW helper functions that can not be used in SophiaFramework

Unavailable BREW helper functions Substitute macros, operators, functions, and classes
MALLOC, ERR_MALLOC MemoryAllocate / new
REALLOC, ERR_REALLOC MemoryReallocate
FREE MemoryFree / new
STRDUP, ERR_STRDUP SFXAnsiString
WSTRDUP SFXWideString

27.2.6. Functions for Memory Tracing on the BREW Simulator

When the TARGET_ENVIRONMENT_SIMULATOR macro is defined, you can trace the memory on the BREW Simulator if the SFDWatcher classs is used for memory operation.

Reference: SFDWatcher