tac0S
Template Affectional Command Operating System
|
The following class defines a "bitmap" – an array of bits, each of which can be independently set, cleared, and tested. More...
#include <bitmap.h>
Public Member Functions | |
BitMap (int nitems) | |
Initialize a bitmap, with "nitems" bits. More... | |
~BitMap () | |
initially, all bits are cleared. More... | |
void | Mark (int which) |
Set the "nth" bit. More... | |
void | Clear (int which) |
Clear the "nth" bit. More... | |
bool | Test (int which) |
Is the "nth" bit set? More... | |
int | Find () |
Return the # of a clear bit, and as a side. More... | |
int | NumClear () |
Return the number of clear bits. More... | |
void | Print () |
Print contents of bitmap. More... | |
void | FetchFrom (OpenFile *file) |
fetch contents from disk More... | |
void | WriteBack (OpenFile *file) |
write contents to disk More... | |
The following class defines a "bitmap" – an array of bits, each of which can be independently set, cleared, and tested.
Most useful for managing the allocation of the elements of an array – for instance, disk sectors, or main memory pages. Each bit represents whether the corresponding sector or page is in use or free.
BitMap::BitMap | ( | int | nitems | ) |
Initialize a bitmap, with "nitems" bits.
BitMap::BitMap Initialize a bitmap with "nitems" bits, so that every bit is clear. it can be added somewhere on a list.
[in] | nitems | is the number of bits in the bitmap. |
BitMap::~BitMap | ( | ) |
initially, all bits are cleared.
BitMap::~BitMap De-allocate a bitmap.
void BitMap::Clear | ( | int | which | ) |
Clear the "nth" bit.
BitMap::Clear Clear the "nth" bit in a bitmap.
[in] | which | is the number of the bit to be cleared. |
void BitMap::FetchFrom | ( | OpenFile * | file | ) |
fetch contents from disk
BitMap::FetchFromFile Initialize the contents of a bitmap from a Nachos file.
[in] | file | is the place to read the bitmap from |
int BitMap::Find | ( | ) |
Return the # of a clear bit, and as a side.
BitMap::Find Return the number of the first bit which is clear. As a side effect, set the bit (mark it as in use). (In other words, find and allocate a bit.)
If no bits are clear, return -1.
void BitMap::Mark | ( | int | which | ) |
Set the "nth" bit.
BitMap::Set Set the "nth" bit in a bitmap.
[in] | which | is the number of the bit to be set. |
int BitMap::NumClear | ( | ) |
Return the number of clear bits.
void BitMap::Print | ( | ) |
Print contents of bitmap.
BitMap::Print Print the contents of the bitmap, for debugging.
Could be done in a number of ways, but we just print the #'s of all the bits that are set in the bitmap.
bool BitMap::Test | ( | int | which | ) |
Is the "nth" bit set?
BitMap::Test Return TRUE if the "nth" bit is set.
[in] | which | is the number of the bit to be tested. |
void BitMap::WriteBack | ( | OpenFile * | file | ) |
write contents to disk
BitMap::WriteBack Store the contents of a bitmap to a Nachos file.
file | is the place to write the bitmap to |