![]() ![]() ![]()
|
BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1 |


SFXHeap Class and SFXClusterHeap Class
Both the SFXHeap class and the SFXClusterHeap class provide the dynamic heap management function.
The SFXClusterHeap class provides the block allocation mechanism, but the SFXHeap class does not.
If the heap size is not updated frequently, using the SFXHeap class is recommended from the perspective of memory efficiency.
Attach Function and Detach Function
The SFXHeap::Attach function delegates the control privilege of Void data to the SFXHeap object. The SFXHeap::Detach function has the reverse functionality.
What is delegation?: In object oriented programming, delegation means that an object have another deputy object behave like itself.
Example 473. How to Use the Attach Function
SFXHeap<SInt16> heap; VoidPtr swap; // allocate memory swap = MemoryAllocate(10240); ... // delegate the control privilege of Void data(swap) to the SFXHeap object(heap) heap.Attach(swap, 10240); // hereafter, the Void data(swap) will be handled as the SFXHeap object ・・・ // after used, the allocated memory will be released automatically
Example 474. How to Use the Detach Function
SFXHeap heap; VoidPtr swap; UInt32 length; ... // delegate the control privilege of SFXHeap object(heap) to the Void data(swap) swap = heap.Detach(&length); // hereafter, the SFXHeap object(heap) will be handled as the Void data(swap) ... // after used, the Void data(swap) must be released explicitly MemoryFree(swap);
| Constructor/Destructor |
|---|
|
SFXHeap( Void ) Constructor of SFXHeap class.
|
| Public Functions | |
|---|---|
| SFCError |
Attach(
VoidPtr heap
, UInt32 size
) Delegate the control privilege of specified Void data to the SFXHeap object.
|
| Bool |
Contains(
VoidConstPtr heap
, UInt32 size
) Check whether the attached SFXHeap object contains some of the specified data of Void type or not.
|
| VoidPtr |
Detach(
UInt32Ptr size = null
) Delegate the control privilege of SFXHeap object to the specified Void data.
|
| static SFXHeap< T > const & |
EmptyInstance( Void ) Get an empty heap.
|
| Void |
Free( Void ) Release the heap that the SFXHeap object manages.
|
| VoidPtr |
GetHeap( Void ) Get the pointer to the heap that the SFXHeap object manages.
|
| VoidConstPtr |
GetHeap( Void ) Get the pointer to the heap that the SFXHeap object manages.
|
| UInt32 |
GetSize( Void ) Get the heap size.
|
| VoidConstPtr |
Protect(
VoidConstPtr heap
, UInt32 size
) Allocate the specified heap safely.
|
| SFCError |
Resize(
UInt32 size
) Set the heap size.
|
| Void |
Unprotect(
VoidConstPtr protect
, VoidConstPtr heap
) Release the heap allocated by the SFXHeap::Protect function.
|
| Bool |
operator==(
SFXHeap< T > const & left
, SFXHeap< M > const & right
) operator==( VoidConstPtr left , SFXHeap< T > const & right ) operator==( SFXHeap< T > const & left , VoidConstPtr right ) Check the relation of "==".
|
| Bool |
operator>=(
SFXHeap< T > const & left
, SFXHeap< M > const & right
) operator>=( VoidConstPtr left , SFXHeap< T > const & right ) operator>=( SFXHeap< T > const & left , VoidConstPtr right ) Check the relation of ">=".
|
| Bool |
operator>(
SFXHeap< T > const & left
, SFXHeap< M > const & right
) operator>( VoidConstPtr left , SFXHeap< T > const & right ) operator>( SFXHeap< T > const & left , VoidConstPtr right ) Check the relation of ">".
|
| Bool |
operator<=(
SFXHeap< T > const & left
, SFXHeap< M > const & right
) operator<=( VoidConstPtr left , SFXHeap< T > const & right ) operator<=( SFXHeap< T > const & left , VoidConstPtr right ) Check the relation of "<=".
|
| Bool |
operator<(
SFXHeap< T > const & left
, SFXHeap< M > const & right
) operator<( VoidConstPtr left , SFXHeap< T > const & right ) operator<( SFXHeap< T > const & left , VoidConstPtr right ) Check the relation of "<".
|
| Bool |
operator!=(
SFXHeap< T > const & left
, SFXHeap< M > const & right
) operator!=( VoidConstPtr left , SFXHeap< T > const & right ) operator!=( SFXHeap< T > const & left , VoidConstPtr right ) Check the relation of "!=".
|
| Bool |
operator==(
SFXHeap< T > const & left
, SFXHeap< M > const & right
) operator==( VoidConstPtr left , SFXHeap< T > const & right ) operator==( SFXHeap< T > const & left , VoidConstPtr right ) Check the relation of "==".
|
[ public, explicit ] SFXHeap(Void);
SFXHeap<SInt16> heap; VoidPtr swap; // allocate memory swap = MemoryAllocate(10240); ... // delegate the control privilege of Void data(swap) to the SFXHeap object(heap) heap.Attach(swap, 10240); // > hereafter, the Void data(swap) will be handled as the SFXHeap object(heap) ・・・ // after used, the allocated memory will be released automatically
[ public, const ] Bool Contains( VoidConstPtr heap // pointer to the heap to compare with UInt32 size // size of heap to compare with (in bytes) );
SFXHeap<SInt16> heap1; heap1.Resize(sizeof(SInt16) * 128); // set the size of heap1 to 256 bytes SFXHeap<SInt16> heap2; // heap2 is that the both ends of heap1 are cut by 10 bytes respectively heap2.Attach(static_cast<BytePtr>(heap1.GetHeap()) + 10, heap1.GetSize() - 20); if (heap2.Contains(heap1.GetHeap(), heap1.GetSize())) { // since heap2 contains heap1, this segment is executed ... } else { // this segment is not executed ... }
[ public ] VoidPtr Detach( UInt32Ptr size = null // pointer to the variable where heap size is stored );
Return the pointer to the heap that the SFXHeap object has.
The heap that the SFXHeap object has is never copied.
The size of heap that the SFXHeap object has is returned to the size argument.
SFXHeap heap; VoidPtr swap; UInt32 length; ... // delegate the control privilege of SFXHeap object(heap) to the Void data(swap) swap = heap.Detach(&length); // hereafter, the SFXHeap object(heap) will be handled as the Void data(swap) ... // after used, the Void data(swap) must be released explicitly MemoryFree(swap);
[ public, static ] SFXHeap< T > const & EmptyInstance(Void);
Get an instance that represents an empty heap.
[ public ] Void Free(Void);
SFXHeap<SInt16> heap;
...
heap.Free(); // release heap explicitly
[ public ] VoidPtr GetHeap(Void);
[ public, const ] VoidConstPtr GetHeap(Void);
Return the pointer to the heap that the SFXHeap object manages.
SFXHeap<SInt16> heap; // set heap size if (heap.Resize(sizeof(SInt16) * 128) == SFERR_NO_ERROR) { TRACE("addr = 0x%08X", heap.GetHeap()); // addr = 0x0686FF80 }
[ public, const ] UInt32 GetSize(Void);
Return the heap size.
SFXHeap<SInt16> heap; // set heap size if (heap.Resize(sizeof(SInt16) * 128) == SFERR_NO_ERROR) { TRACE("size = %d", heap.GetSize()); // size = 256 }
[ public, const ] VoidConstPtr Protect( VoidConstPtr heap // pointer to the heap to allocate safely UInt32 size // heap size to allocate safely );
Return a pointer to the allocated heap.
If the SFXHeap object contains some of the specified heap, allocate another heap where the specified heap is moved. Otherwise, allocate the specified heap that will not be moved. And return a pointer to the allocated heap.
To release the heap allocated by the SFXHeap::Protect function, use the SFXHeap::Unprotect function.
SFXHeap<SInt16> heap1; SFXHeap<SInt16> heap2; VoidConstPtr protect; heap1.Resize(sizeof(UInt32) * 128); // set the heap size to 512 bytes heap2.Resize(sizeof(UInt32) * 128); // set the heap size to 512 bytes // save values not to conflict when processing themselves VoidConstPtr sa(heap2.GetHeap()); UInt32 ss(heap2.GetSize()); UInt32 ds(heap1.GetSize()); TRACE("addr = 0x%08X", heap1.GetHeap()); // addr = 0x06871C84 // allocate another heap safely if ((protect = heap1.Protect(sa, ss)) != null) { TRACE("addr = 0x%08X", protect); // addr = 0x06871EB8 // release the heap allocated by the SFXHeap::Protect function heap1.Unprotect(protect, sa); }
SFXClusterHeap::Unprotect | SFXHeap::Attach | SFXHeap::Contains
SFXHeap<SInt16> heap;
heap.Resize(sizeof(UInt32) * 128); // set the heap size to 512 bytes
[ public, const ] Void Unprotect( VoidConstPtr protect // pointer the function returns VoidConstPtr heap // pointer to the heap that the function allocates );
Release the heap allocated by the SFXHeap::Protect function.
SFXHeap<SInt16> heap1; SFXHeap<SInt16> heap2; VoidConstPtr protect; heap1.Resize(sizeof(UInt32) * 128); // set the heap size to 512 bytes heap2.Resize(sizeof(UInt32) * 128); // set the heap size to 512 bytes // save values not to conflict when processing themselves VoidConstPtr sa(heap2.GetHeap()); UInt32 ss(heap2.GetSize()); UInt32 ds(heap1.GetSize()); TRACE("addr = 0x%08X", heap1.GetHeap()); // addr = 0x06871C84 // allocate another heap safely if ((protect = heap1.Protect(sa, ss)) != null) { TRACE("addr = 0x%08X", protect); // addr = 0x06871EB8 // release the heap allocated by the SFXHeap::Protect function // The value of 2nd argument of Unprotect function must be the same with that of 1st argument of Protect function heap1.Unprotect(protect, sa); }
[ public, const ] operator T *(Void);
If heap is allocated, return a pointer to the heap. Otherwise return a null pointer.
[ public, friend ] Bool operator==( SFXHeap< T > const & left // SFXHeap object to compare with SFXHeap< M > const & right // SFXHeap object to compare with );
[ public, friend ] Bool operator==( SFXHeap< T > const & left // SFXHeap object to compare with VoidConstPtr right // pointer to the heap to compare with );
[ public, friend ] Bool operator==( VoidConstPtr left // pointer to the heap to compare with SFXHeap< T > const & right // SFXHeap object to compare with );
Both head address of left heap and that of right heap are compared with.
[ public, friend ] Bool operator>=( SFXHeap< T > const & left // SFXHeap object to compare with SFXHeap< M > const & right // SFXHeap object to compare with );
[ public, friend ] Bool operator>=( SFXHeap< T > const & left // SFXHeap object to compare with VoidConstPtr right // pointer to the heap to compare with );
[ public, friend ] Bool operator>=( VoidConstPtr left // pointer to the heap to compare with SFXHeap< T > const & right // SFXHeap object to compare with );
Both head address of left heap and that of right heap are compared with.
[ public, friend ] Bool operator>( SFXHeap< T > const & left // SFXHeap object to compare with SFXHeap< M > const & right // SFXHeap object to compare with );
[ public, friend ] Bool operator>( SFXHeap< T > const & left // SFXHeap object to compare with VoidConstPtr right // pointer to the heap to compare with );
[ public, friend ] Bool operator>( VoidConstPtr left // pointer to the heap to compare with SFXHeap< T > const & right // SFXHeap object to compare with );
Both head address of left heap and that of right heap are compared with.
[ public, friend ] Bool operator<=( SFXHeap< T > const & left // SFXHeap object to compare with SFXHeap< M > const & right // SFXHeap object to compare with );
[ public, friend ] Bool operator<=( SFXHeap< T > const & left // SFXHeap object to compare with VoidConstPtr right // pointer to the heap to compare with );
[ public, friend ] Bool operator<=( VoidConstPtr left // pointer to the heap to compare with SFXHeap< T > const & right // SFXHeap object to compare with );
Both head address of left heap and that of right heap are compared with.
[ public, friend ] Bool operator<( SFXHeap< T > const & left // SFXHeap object to compare with SFXHeap< M > const & right // SFXHeap object to compare with );
[ public, friend ] Bool operator<( SFXHeap< T > const & left // SFXHeap object to compare with VoidConstPtr right // pointer to the heap to compare with );
[ public, friend ] Bool operator<( VoidConstPtr left // pointer to the heap to compare with SFXHeap< T > const & right // SFXHeap object to compare with );
Both head address of left heap and that of right heap are compared with.
[ public, friend ] Bool operator!=( SFXHeap< T > const & left // SFXHeap object to compare with SFXHeap< M > const & right // SFXHeap object to compare with );
[ public, friend ] Bool operator!=( SFXHeap< T > const & left // SFXHeap object to compare with VoidConstPtr right // pointer to the heap to compare with );
[ public, friend ] Bool operator!=( VoidConstPtr left // pointer to the heap to compare with SFXHeap< T > const & right // SFXHeap object to compare with );
Both head address of left heap and that of right heap are compared with.
|
Copyright (C) 2002 - 2009 Sophia Cradle, Inc. All Rights Reserved. |
![]() ![]() ![]()
|