1. DEVRY GSP 215 Week 6 iLab Virtual Memory NEW
Check this A+ tutorial guideline at
http://www.homeworkrank.com/gsp-215-devry/gsp-215-
week-6-ilab-virtual-memory-updated
For more classes visit
http://www.homeworkrank.com
Week 6 Lab—Virtual Memory
TCO 9—Given the need to support the runtime creation of
varying quantities of data objects, learn how dynamic memory
allocation can provide this capability in a very efficient way.
TCO 8—Given the need to understand virtual memory, describe
how memory allocation and paging are used to give a computer
program access to more memory than physically available.
Scenario
In this week’s lab, you will override the new and delete
operators for an implementation of linked list.
Rubric
2. Point distribution for this activity
Lab Activity
Document Points possible Points received
Code and screenshot 40
Total Points 40
Generally, the default implementation of new and delete is
sufficient for a given program. At times, you may want to
specialize memory allocation for advanced tasks. You may want
to allocate instances of a certain class from a particular
memory pool, implement your own garbage collector, or
caching.
We will override the new and delete operator in this lab. When
overriding these operators, both need to be overridden. The
new operator allocates memory and creates an object. The
delete operator deallocates memory.
We will be implementing a linked list class and overloading the
new and delete operator. We can improve the speed of
allocating new nodes by keeping a list of deleted nodes and
reusing the memory when new nodes are allocated.
3. The code for the linked list is below. You may also use your own
implementation of linked list.
The overloaded new operator will check a freelist to recycle a
node before going to the heap and getting one that way. The
delete operator will add the node to the freelist.
Hint: Use the following in the Node class.
void * operator new(size_t);
void operator delete(void*);
static void printFreelist();
After the class Node definition, be sure to set the freelist to
NULL.
Node* Node::freelist=NULL;
Implement Node::printFreelist() as well, and in the Main,
include calls to
Node::printFreelist();
to see the nodes in the free list.
Original C++ Code:
#include <iostream>
using namespace std;