SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Protected Member Functions
RWDiskPageHeap Class Reference

Deprecated. Specialized type of buffered page heap that swaps its pages to disk as necessary. More...

#include <rw/diskpage.h>

Inheritance diagram for RWDiskPageHeap:
RWBufferedPageHeap RWVirtualPageHeap

Public Member Functions

 RWDiskPageHeap ()
 
 RWDiskPageHeap (const char *filename, unsigned nbufs=10, unsigned pgsize=512)
 
virtual ~RWDiskPageHeap ()
 
virtual size_t allocate ()
 
virtual void deallocate (size_t h)
 
- Public Member Functions inherited from RWBufferedPageHeap
 RWBufferedPageHeap (unsigned pgsize, unsigned nbufs=10)
 
virtual ~RWBufferedPageHeap ()
 
virtual void dirty (size_t h)
 
bool isValid ()
 
virtual void * lock (size_t h)
 
virtual void unlock (size_t h)
 
- Public Member Functions inherited from RWVirtualPageHeap
 RWVirtualPageHeap (unsigned pgsize)
 
virtual ~RWVirtualPageHeap ()
 
unsigned pageSize () const
 

Protected Member Functions

virtual bool swapIn (size_t, void *)
 
virtual bool swapOut (size_t, void *)
 

Detailed Description

Deprecated:
As of SourcePro 11.1.

RWDiskPageHeap is deprecated and is no longer supported. It may be removed from future releases.

Class RWDiskPageHeap is a specializing type of buffered page heap. It swaps its pages to disk as necessary.

Synopsis
#include <rw/diskpage.h>
unsigned nbufs;
unsigned pagesize;
RWDiskPageHeap heap("filename", nbufs, pagesize) ;
Persistence
None
Example

In this example, 100 nodes of a linked list are created and strung together. The list is then walked, confirming that it contains 100 nodes. Each node is a single page. The "pointer" to the next node is actually the handle for the next page.

#include <iostream>
#include <iomanip>
#include <rw/diskpage.h>
#include <rw/rstream.h>
struct Node
{
int key;
RWHandle next;
};
RWHandle head = 0;
const int N = 100; // Exercise 100 Nodes
int main()
{
// Construct a disk-based page heap with page size equal
// to the size of Node and with 10 buffers:
RWDiskPageHeap heap("pageheap.tmp", 10, sizeof(Node));
if (!heap.isValid()) {
std::cerr << "Unable to open temporary swap file.\n";
std::cerr << "Do you have write privileges?\n" << std::flush;
return 0;
}
// Build the linked list:
for (int i=0; i<N; i++) {
RWHandle h = RWHandle(heap.allocate());
Node* newNode = (Node*)heap.lock(h);
newNode->key = i;
newNode->next = head;
head = h;
heap.dirty(h);
heap.unlock(h);
}
// Now walk the list:
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++;
}
std::cout << "List with " << count << " nodes walked.\n";
// The following line should not be necessary,
// but a bug in Sun C++ requires it:
std::cout << std::flush;
return 0;
}

Program output:

List with 100 nodes walked.

Constructor & Destructor Documentation

RWDiskPageHeap::RWDiskPageHeap ( )

Constructs a new disk-based page heap using a temporary file. The number of buffers, each the size of the page size, is 10. No more than this many pages can be locked at any one time. The size of each page is 512. To see whether a valid RWDiskPageHeap has been constructed, call member function isValid().

Windows users may be required to call AnsiToOEM on a Windows character constant for the filename in this constructor, because this constructor uses a C function call that may resolve to a DOS system call. In that case, DOS might not be able to recognize Windows character sets.

Note
Determining the temporary filename may result in a system call that requires administrator access.
RWDiskPageHeap::RWDiskPageHeap ( const char *  filename,
unsigned  nbufs = 10,
unsigned  pgsize = 512 
)

Constructs a new disk-based page heap. The heap uses a file with filename filename, otherwise it negotiates with the operating system for a temporary filename. The number of buffers, each the size of the page size, is nbufs. No more than this many pages can be locked at any one time. The size of each page is given by pgsize. To see whether a valid RWDiskPageHeap has been constructed, call member function isValid().

Windows users may be required to call AnsiToOEM on a Windows character constant for the filename in this constructor, because this constructor uses a C function call that may resolve to a DOS system call. In that case, DOS might not be able to recognize Windows character sets.

Note
Passing a null pointer for the parameter filename may result in a system call that requires administrator access.
virtual RWDiskPageHeap::~RWDiskPageHeap ( )
virtual

Returns any resources used by the disk page heap back to the operating system. All pages should have been deallocated before the destructor is called.

Member Function Documentation

virtual size_t RWDiskPageHeap::allocate ( )
virtual

Allocates a page off the disk page heap and returns a handle for it. If there is no more space (for example, the disk is full), the function returns 1.

Implements RWBufferedPageHeap.

virtual void RWDiskPageHeap::deallocate ( size_t  h)
virtual

Deallocates the page associated with handle h. It is not an error to deallocate a zero handle.

Reimplemented from RWBufferedPageHeap.

virtual bool RWDiskPageHeap::swapIn ( size_t  h,
void *  buf 
)
protectedvirtual

It is the responsibility of the specializing class to supply a definition for this pure virtual function. The Function swapIn() should copy the page with handle h into the buffer pointed to by buf.

Implements RWBufferedPageHeap.

virtual bool RWDiskPageHeap::swapOut ( size_t  h,
void *  buf 
)
protectedvirtual

It is the responsibility of the specializing class to supply a definition for this pure virtual function. The function swapOut() should copy the page with handle h from the buffer pointed to by buf to the swapping medium.

Implements RWBufferedPageHeap.

Copyright © 2022 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.