バナーをクリックすれば目次に戻ります
Copyright 1999 Rogue Wave Software
Copyright 1999 Sun Microsystems, Inc.
RWDiskPageHeap
RWDiskPageHeap
RWBufferedPageHeap
RWVirtualPageHeap
#include <rw/diskpage.h>
unsigned nbufs;
unsigned pagesize;
RWDiskPageHeap heap("filename", nbufs, pagesize) ;
#include <rw/diskpage.h>
#include <rw/rstream.h>
struct Node {
int key;
RWHandle next;
};
RWHandle head = 0;
const int N = 100; // 100 ノードを実行する
main() {
// ページサイズがノードサイズと等しく、バッファが 10 個の
// ディスクベースのページヒープを作成する
RWDiskPageHeap heap(0, 10, sizeof(Node));
// リンクリストを作成する
for (int i=0; i<N; i++){
RWHandle h = heap.allocate();
Node* newNode = (Node*)heap.lock(h);
newNode->key = i;
newNode->next = head;
head = h;
heap.dirty(h);
heap.unlock(h);
}
// リスト内を検査する
unsigned count = 0;
RWHandle nodeHandle = head;
while(nodeHandle){
Node* node = (Node*)heap.lock(nodeHandle);
RWHandle nextHandle = node->next;
heap.unlock(nodeHandle);
heap.deallocate(nodeHandle);
nodeHandle = nextHandle;
count++;
}
cout << "List with " << count << " nodes walked.\n";
return 0;
}
|
List with 100 nodes walked. |
RWDiskPageHeap(const char* filename = 0,
unsigned nbufs = 10,
unsigned pgsize = 512);
virtual ~RWDiskPageHeap();
virtual RWHandle allocate();
virtual void deallocate(RWHandle h);
virtual void dirty(RWHandle h);
RWBoolean isValid() const;
virtual void* lock(RWHandle h);
virtual void unlock(RWHandle h);
