rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWDiskPageHeap Class Reference
[File System]

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

List of all members.

Public Member Functions

 RWDiskPageHeap (const char *filename=0, unsigned nbufs=10, unsigned pgsize=512)
virtual ~RWDiskPageHeap ()
virtual size_t allocate ()
virtual void deallocate (size_t h)

Protected Member Functions

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

Detailed Description

Deprecated:
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

Examples

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 ( const char *  filename = 0,
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 
) [protected, virtual]

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 
) [protected, virtual]

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.

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.