![]() ![]() ![]()
|
BREW C++ ライブラリ & GUI フレームワーク & XML ミドルウェア : SophiaFramework UNIVERSE 5.0 |


SFXHeap クラスと SFXClusterHeap クラス
SFXHeap クラスと SFXClusterHeap クラスは、動的なヒープ管理を提供するクラスです。
SFXClusterHeap クラスはブロックアロケーションを行いますが、SFXHeap クラスはブロックアロケーションを行いません。
ヒープサイズの変更頻度が少ない場合、SFXHeap クラスを使う方がメモリ効率が良くなります。
Attach 関数 と Detach 関数
SFXHeap::Attach 関数は、指定した型のデータの動作と管理権限を SFXHeap クラスのインスタンスにデリゲート(委譲) します。 SFXHeap::Detach 関数はその逆の操作を行います。
デリゲートとは : オブジェクト指向プログラミングにおいて、あるオブジェクトの振る舞いを別のオブジェクトに肩代わりして振る舞ってもらうことです。 日本語では、「委譲」と訳されます。
| コンストラクタ/デストラクタ |
|---|
|
SFXHeap( Void ) SFXHeap クラスのコンストラクタです。
|
[ public, explicit ] SFXHeap(Void);
SFXHeap<SInt16> heap; VoidPtr swap; // メモリを割り当てる swap = MemoryAllocate(10240); ... // Void 型データ swap の動作と管理権限を SFXHeap クラスのインスタンス heap にデリゲートする heap.Attach(swap, 10240); // 以降、Void 型データ swap を SFXHeap クラスのインスタンス heap として操作できる ・・・ // 使用後、割り当てたメモリは自動的に解放される
[ public, const ] Bool Contains( VoidConstPtr heap // 比較するヒープへのポインタ UInt32 size // 比較するヒープのサイズ(バイト単位) );
SFXHeap<SInt16> heap1; heap1.Resize(sizeof(SInt16) * 128); // heap1 のサイズを 256 バイトに設定する SFXHeap<SInt16> heap2; // heap2 は heap1 の両端を 10 バイトずつ削ったもの heap2.Attach(static_cast<BytePtr>(heap1.GetHeap()) + 10, heap1.GetSize() - 20); if (heap2.Contains(heap1.GetHeap(), heap1.GetSize())) { // 共通部分があるので、ここが実行される ... } else { // ここは実行されない ... }
SFXHeap クラスのインスタンスが持っていたヒープへのポインタを返します。
SFXHeap クラスのインスタンスが持つヒープはコピーされません。
size パラメータには SFXHeap クラスのインスタンスが持っていたヒープサイズが返されます。
SFXHeap heap; VoidPtr swap; UInt32 length; ... // SFXHeap クラスのインスタンス heap の動作と管理権限を Void 型データ swap にデリゲートする swap = heap.Detach(&length); // 以降、SFXHeap クラスのインスタンス を Void 型データ swap として操作する ... // 使用後、Void 型データ swap のメモリを解放する必要がある MemoryFree(swap);
[ public, static ] SFXHeap< T > const & EmptyInstance(Void);
空のヒープを表すインスタンスを取得します。
[ public ] Void Free(Void);
SFXHeap<SInt16> heap;
...
heap.Free(); // 明示的にヒープを解放する
[ public ] VoidPtr GetHeap(Void);
[ public, const ] VoidConstPtr GetHeap(Void);
SFXHeap クラスのインスタンスが管理しているヒープへのポインタを返します。
SFXHeap<SInt16> heap; // ヒープのサイズ設定する if (heap.Resize(sizeof(SInt16) * 128) == SFERR_NO_ERROR) { TRACE("addr = 0x%08X", heap.GetHeap()); // addr = 0x0686FF80 }
[ public, const ] UInt32 GetSize(Void);
ヒープサイズを返します。
SFXHeap<SInt16> heap; // ヒープのサイズを設定する if (heap.Resize(sizeof(SInt16) * 128) == SFERR_NO_ERROR) { TRACE("size = %d", heap.GetSize()); // size = 256 }
[ public, const ] VoidConstPtr Protect( VoidConstPtr heap // ヒープへのポインタ UInt32 size // ヒープのサイズ );
割り当てたヒープへのポインタを返します。
SFXHeap オブジェクトのヒープと指定したヒープとの間に共通部分がある場合、 新たなヒープを確保し指定したヒープの内容を移動します。共通部分がない場合は、指定したヒープをそのまま割り当てます。
SFXHeap::Protect 関数で割り当てたヒープを解放するには、Unprotect 関数を使います。
SFXHeap<SInt16> heap1; SFXHeap<SInt16> heap2; VoidConstPtr protect; heap1.Resize(sizeof(UInt32) * 128); // ヒープのサイズを 512 バイトに設定する heap2.Resize(sizeof(UInt32) * 128); // ヒープのサイズを 512 バイトに設定する // 自分自身と演算するときに競合しないように値を保存する VoidConstPtr sa(heap2.GetHeap()); UInt32 ss(heap2.GetSize()); UInt32 ds(heap1.GetSize()); TRACE("addr = 0x%08X", heap1.GetHeap()); // addr = 0x06871C84 // 別のヒープを割り当てる if ((protect = heap1.Protect(sa, ss)) != null) { TRACE("addr = 0x%08X", protect); // addr = 0x06871EB8 // ヒープを解放する heap1.Unprotect(protect, sa); }
SFXHeap<SInt16> heap;
heap.Resize(sizeof(UInt32) * 128); // ヒープのサイズを 512 バイトに設定する
[ public, const ] Void Unprotect( VoidConstPtr protect // が返したポインタ VoidConstPtr heap // の割り当てたヒープへのポインタ );
SFXHeap::Protect 関数で設定したヒープを解放します。
SFXHeap<SInt16> heap1; SFXHeap<SInt16> heap2; VoidConstPtr protect; heap1.Resize(sizeof(UInt32) * 128); // ヒープのサイズを 512 バイトに設定する heap2.Resize(sizeof(UInt32) * 128); // ヒープのサイズを 512 バイトに設定する // 自分自身と演算するときに競合しないように値を保存する VoidConstPtr sa(heap2.GetHeap()); UInt32 ss(heap2.GetSize()); UInt32 ds(heap1.GetSize()); TRACE("addr = 0x%08X", heap1.GetHeap()); // addr = 0x06871C84 // 別のヒープを割り当てる if ((protect = heap1.Protect(sa, ss)) != null) { TRACE("addr = 0x%08X", protect); // addr = 0x06871EB8 heap1.Unprotect(protect, sa); // ヒープを解放する // Unprotect の第 2 引数は Protect の第 1 引数と同じ値にする }
[ public, const ] operator T *(Void);
ヒープが割り当てられている場合はそのヒープへのポインタを、 割り当てられていない場合は空ポインタを返します。
[ public, friend ] Bool operator==( SFXHeap< T > const & left // 比較する SFXHeap 型オブジェクト SFXHeap< M > const & right // 比較する SFXHeap 型オブジェクト );
[ public, friend ] Bool operator==( SFXHeap< T > const & left // 比較する SFXHeap 型オブジェクト VoidConstPtr right // 比較するヒープへのポインタ );
[ public, friend ] Bool operator==( VoidConstPtr left // 比較するヒープへのポインタ SFXHeap< T > const & right // 比較する SFXHeap 型オブジェクト );
ヒープの先頭アドレスを比較します。
[ public, friend ] Bool operator>=( SFXHeap< T > const & left // 比較する SFXHeap 型オブジェクト SFXHeap< M > const & right // 比較する SFXHeap 型オブジェクト );
[ public, friend ] Bool operator>=( SFXHeap< T > const & left // 比較する SFXHeap 型オブジェクト VoidConstPtr right // 比較するヒープへのポインタ );
[ public, friend ] Bool operator>=( VoidConstPtr left // 比較するヒープへのポインタ SFXHeap< T > const & right // 比較する SFXHeap 型オブジェクト );
ヒープの先頭アドレスを比較します。
[ public, friend ] Bool operator>( SFXHeap< T > const & left // 比較する SFXHeap 型のオブジェクト SFXHeap< M > const & right // 比較する SFXHeap 型のオブジェクト );
[ public, friend ] Bool operator>( SFXHeap< T > const & left // 比較する SFXHeap 型のオブジェクト VoidConstPtr right // 比較するヒープへのポインタ );
[ public, friend ] Bool operator>( VoidConstPtr left // 比較するヒープへのポインタ SFXHeap< T > const & right // 比較する SFXHeap 型のオブジェクト );
ヒープの先頭アドレスを比較します。
[ public, friend ] Bool operator<=( SFXHeap< T > const & left // 比較する SFXHeap 型オブジェクト SFXHeap< M > const & right // 比較する SFXHeap 型オブジェクト );
[ public, friend ] Bool operator<=( SFXHeap< T > const & left // 比較する SFXHeap 型オブジェクト VoidConstPtr right // 比較するヒープへのポインタ );
[ public, friend ] Bool operator<=( VoidConstPtr left // 比較するヒープへのポインタ SFXHeap< T > const & right // 比較する SFXHeap 型オブジェクト );
ヒープの先頭アドレスを比較します。
[ public, friend ] Bool operator<( SFXHeap< T > const & left // 比較する SFXHeap 型オブジェクト SFXHeap< M > const & right // 比較する SFXHeap 型オブジェクト );
[ public, friend ] Bool operator<( SFXHeap< T > const & left // 比較する SFXHeap 型オブジェクト VoidConstPtr right // 比較するヒープへのポインタ );
[ public, friend ] Bool operator<( VoidConstPtr left // 比較するヒープへのポインタ SFXHeap< T > const & right // 比較する SFXHeap 型オブジェクト );
ヒープの先頭アドレスを比較します。
[ public, friend ] Bool operator!=( SFXHeap< T > const & left // 比較する SFXHeap 型オブジェクト SFXHeap< M > const & right // 比較する SFXHeap 型オブジェクト );
[ public, friend ] Bool operator!=( SFXHeap< T > const & left // 比較する SFXHeap 型オブジェクト VoidConstPtr right // 比較するヒープへのポインタ );
[ public, friend ] Bool operator!=( VoidConstPtr left // 比較するヒープへのポインタ SFXHeap< T > const & right // 比較する SFXHeap 型オブジェクト );
ヒープの先頭アドレスを比較します。
|
Copyright (C) 2002 - 2008 Sophia Cradle Incorporated All Rights Reserved. |
![]() ![]() ![]()
|