assign6 C++ Guide

Written by Nick Troccoli

C++ Maps

C++ has a type unordered_map that will be useful on this assignment (map sorts its contents, which isn't needed for this assignment).

#include <unordered_map> to use it.

assign0 provided an introduction to C++ maps; check out that assignment handout for a refresher.

Note that you can have various types as values, including your own custom struct type:

typedef struct {
    ...
} MyStruct;

...

unordered_map<int, MyStruct> numToStructMap;

Remember also that when using [] syntax, if that key is not in the map, using [] will insert it! This is called auto-insertion, and is sometimes useful, but can also cause problems. Therefore, it's good practice to check if something is in a map first before you try to access it.

Destructors

On this assignment, the VirtualMemoryRegion destructor will need to remove all page mappings and give back all the physical pages it's using before it's deleted (that way another virtual address space that's still around can use them). The destructor has the name ~ClassName, e.g. ~VirtualMemoryRegion. assign0 provided an introduction to destructors; check out that assignment handout for a refresher.