SophiaFramework UNIVERSE 5.3 |
SFDWatcher class records all the memory operation.
This class does nothing on the mobile phone device.
Public Functions | |
---|---|
static Void |
dumpleak( Void ) Dump information on un-released heap.
|
static Void |
dumpuse( Void )
Dump the current size of total heap and the maximum size of total heap.
|
static Void |
free(
VoidPtr address
) Free the heap.
|
static VoidPtr |
malloc(
UInt32 size
, ACharConstPtr file
, SInt32 line
) Allocate memory from heap.
|
static VoidPtr |
realloc(
VoidPtr address
, UInt32 size
, ACharConstPtr file
, SInt32 line
) Re-allocate memory from heap
|
static Void |
resetlimit( Void ) Reset the upper limit of total heap size.
|
static Void |
resetmaximum( Void ) Set the maximum size of total heap to the current size of total heap.
|
static Void |
setlimit(
UInt32 size
) Set the upper limit of total heap size that can be allocated.
|
static Void |
setrandomize(
Bool active
) Enable or disable to write random data to the allocated memory.
|
static Void |
setwarning(
Bool active
) Enable or disable to warn about an invalid argument.
|
[ public, static ] Void dumpleak(Void);
The SFDWatcher::dumpleak function is used to display information on un-released heap in the output window of BREW simulator.
[ public, static ] Void dumpuse(Void);
The SFDWatcher::dumpuse function is used to display the current size of total heap and the maximum size of total heap in the output window of BREW simulator.
The SFDWatcher::free function is used to free the heap specified with the "address" argument.
When the "address" argument is set to "null" and warning option about invalid arguments is set effective by the SFDWatcher::setwarning funtion, "null" is displayed as the value of "address" argument in the output window of BREW simulator.
SFDWatcher::setwarning | Section 27.2.3, “MemoryFree Macro” | Section 27.2.4, “The new/delete Operators”
[ public, static ] VoidPtr malloc( UInt32 size // heap size to be allocated ( bytes ) ACharConstPtr file // source code name of caller SInt32 line // line number of caller );
Return a pointer to the allocated heap.
After confirmation whether heap has enough free memory space or not, memory is allocated by the SFXHelper::malloc function and the file name and line number of caller are recorded.
The file argument ( source file name of caller ) and line argument ( line number of caller ) are specified optionally when debugging. The file argument can be set to the "null" pointer.
If heap allocation is failed, the "null" pointer is returned. When heap does not have enough free memory space, the "null" pointer will be displayed in the output window of BREW simulator.
When the size argument is set to 0 and warning option about invalid arguments is set effective by the SFDWatcher::setwarning function, 0 ( value of size ) is displayed in the output window of BREW simulator.
This is an example that "the 100th line of Test.cpp resource file" is recorded and heap is allocated.
// resource file name is HogeHoge.cpp ... // in fact this is the 4096th line UInt32Ptr buf = reinterpret_cast<UInt32Ptr>(SFDWatcher::malloc(sizeof(UInt32) * 1000, "Test.cpp", 100)); ...
When recording the source file name and line number and allocating heap, the MemoryAllocate macro or new operator is more useful.
SFDWatcher::setwarning | SFXHelper::malloc | MemoryAllocate | new
[ public, static ] VoidPtr realloc( VoidPtr address // pointer to the space allocated before or an empty pointer UInt32 size // the new size of heap to be allocated in byte ACharConstPtr file // the source code name of the caller SInt32 line // the line number of the caller );
The SFDWatcher::realloc function returns the pointer to re-allocated heap.
After confirmation whether heap has enough free memory space or not, memory is re-allocated by the SFXHelper::realloc function and the file name and line number of caller are recorded.
When re-allocating heap, the previous content is retained if memory size to be newly re-allocated is bigger than before.
While memory size is smaller than before, only the previous content of newly re-allocated heap is retained.
When the address argument is set to the null pointer, heap is newly allocated. This is the same as the SFDWatcher::malloc function.
The file argument ( source file name of caller ) and line argument ( line number of caller ) are specified optionally when debugging. The file argument can be set to the "null" pointer.
If heap allocation is failed, the "null" pointer is returned. When heap does not have enough free memory space, the "null" pointer will be displayed in the output window of BREW simulator.
When the address argument is set to other than the null pointer and the size argument is set to 0, its heap is released. The result is the same as the SFDWatcher::free function.
[ public, static ] Void resetlimit(Void);
The SFDWatcher::resetlimit function resets the upper limit of total heap size set by the SFDWatcher::setlimit function.
SFDWatcher::setlimit | SFDWatcher::malloc | SFDWatcher::realloc
[ public, static ] Void resetmaximum(Void);
Though the size of total heap changes by using the SFDWatcher::malloc, SFDWatcher::realloc, or SFDWatcher::free function, SophiaFramework has its maximum size internally.
The SFDWatcher::resetmaximum function resets the former maximum size of total heap, and sets the current size of total heap to the maximum size of total heap.
The SFDWatcher::setlimit function sets the upper limit of total heap size that can be allocated.
The free heap size that can be confirmed inside the SFDWatcher::malloc function or SFDWatcher::realloc function is the value gotten by subtracting the total allocated heap size from this upper limit.
There is no upper limit for total heap size until the SFDWatcher::setlimit function is called. (Actually, the maximum heap size of BREW simulator is the upper limit.)
SFDWatcher::resetlimit | SFDWatcher::malloc | SFDWatcher::realloc
The SFDWatcher::setrandomize function is used to enable or disable to write random data to the allocated memory.
By using this function, it is easier to detect the bugs caused by forgetting memory initialization when debugging with the BREW simulator.
In case this function is set to "off", allocated memory is padded with "null". By default this function is set to "on".
The SFDWatcher::setwarning function is used to enable or disable to display the warning message in the output window of BREW simulator when an invalid argument is specified with the SFDWatcher::malloc, SFDWatcher::realloc, or SFDWatcher::free function.
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |