Tools.h++ Manual
104011 Tandem Computers Incorporated 21-99
21
Program output:
List with 100 nodes walked.
RWHandle h = 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++;
}
cout << "List with " << count << " nodes walked.\n";
return 0;
}
Code Example 21-2 (Continued)