I lied, now the constructor is finished.

This commit is contained in:
Alex 2017-06-19 09:34:49 -05:00
parent 9d18451b26
commit 7cfd4eb536

View file

@ -137,7 +137,8 @@ ContFramePool::ContFramePool(unsigned long _base_frame_no,
// since as stated in the instructions it is already big enough to
// hold for 128MB of memory with one bit per frame, so should still
// be enough for 64MB of memory with 2 bits per frame.
assert(_n_frames <= FRAME_SIZE * 8);
// Assertion changed to match max size of frames allowed.
assert(_n_frames <= FRAME_SIZE * 4);
base_frame_no = _base_frame_no;
nframes = _n_frames;
@ -147,47 +148,53 @@ ContFramePool::ContFramePool(unsigned long _base_frame_no,
// If _info_frame_no is zero then we keep management info in the first
// frame(s), else we use the provided frame(s) to keep management info
// NOTE: need a second check for the number of info frames specified, if any.
// NOTE: bitmap needs to be allocated with n_info_frames if specified.
if(info_frame_no == 0)
{
if(n_info_frames == 0)
{
bitmap = (unsigned char *) (base_frame_no * FRAME_SIZE);
}
else
{
bitmap = (unsigned char *) (base_frame_no * FRAME_SIZE * n_info_frames);
}
}
else
{
if(n_info_frames == 0)
{
bitmap = (unsigned char *) (info_frame_no * FRAME_SIZE);
}
else
{
bitmap = (unsigned char *) (info_frame_no * FRAME_SIZE * n_info_frames);
}
}
// Number of frames must "fill" the bitmap!
assert ((nframes % 8 ) == 0);
// Everything ok. Proceed to mark all bits in the bitmap
// NOTE: I don't think this needs to be changed...
for(int i=0; i*8 < _n_frames; i++)
// NOTE: changed to reflect that I need 2 bits per frame now
for(int i=0; i*4 < _n_frames; i++)
{
bitmap[i] = 0xFF;
}
// Mark the first frame as being used if it is being used
// NOTE: need to mark multiple frames if needed.
unsigned long i = info_frame_no;
while(i < (info_frame_no + n_info_frames))
if(info_frame_no == 0)
{
bitmap[i*8] = 0x7F;
bitmap[0] = 0x3F;
nFreeFrames--;
}
else
{
unsigned int i = info_frame_no / 4;
unsigned int r = info_frame_no % 4;
unsigned char mask = 0xC0;
mask = mask >> r*2;
unsigned int c = 0;
while(c < n_info_frames)
{
bitmap[i] = bitmap[i] ^ mask;
if(mask == 0x00)
{
i++;
mask = 0xC0;
}
c++;
}
nFreeFrames--;
}
@ -196,8 +203,41 @@ ContFramePool::ContFramePool(unsigned long _base_frame_no,
unsigned long ContFramePool::get_frames(unsigned int _n_frames)
{
// TODO: IMPLEMENTATION NEEEDED!
assert(false);
// Are there enough frames left to allocate?
assert(nFreeFrames > _n_frames);
// Find a frame that is not being used and return its frame index.
// Mark that frame as being used in the bitmap.
// NOTE: Must be updated to find a sequence of contiguous frames
// that are not being used and update the index of the head.
unsigned int frame_no = base_frame_no;
unsigned int i = 0;
unsigned int c = 0;
while (true) {
if(bitmap[i] != 0x0)
{
while(c < _n_frames)
{
}
}
i++;
}
frame_no += i * 8;
unsigned char mask = 0x80;
while ((mask & bitmap[i]) == 0) {
mask = mask >> 1;
frame_no++;
}
nFreeFrames--;
// Update bitmap
bitmap[i] = bitmap[i] ^ mask;
return (frame_no);
}
void ContFramePool::mark_inaccessible(unsigned long _base_frame_no,