Question

Implement and demonstrate a disk-based buffer pool class based on the LRU buffer pool replacement strategy....

Implement and demonstrate a disk-based buffer pool class based on the LRU buffer pool replacement strategy. Disk blocks are numbered consecutively from the beginning of the file with the first block numbered as 0. Assume that blocks are 4096 bytes in size. Use the supplied C++ files to implement your LRU Buffer Pool based on the instructions below. • Implement a BufferBlock class using the supplied BufferBlockADT.h o Your Buffer Block must inherit BufferBlockADT or you will not get credit for your work. o All BufferBlockADT virtual functions must be implemented in BufferBlock o Block Size: 4096 bytes o Add an instance variable to your buffer block implementation to store the block id; i.e., “int blockID.” • Implement a Buffer Pool by inheriting BufferPoolADT (BufferPoolADT.h) – implement all of BufferPoolADT’s functions (if you do not inherit BufferPoolADT you will not get credit for your work). o Your buffer pool should consist of 5 buffer blocks o Your buffer pool should manage the buffers using the LRU strategy o Your buffer pool should be named LRUBufferPool and the file containing the LRUBufferPool class should be named LRUBufferPool.h • Use the provided main.cpp and the included test file mydatafile.txt to test your program. File Provided: • BufferBlockADT.h • BufferPoolADT.h • constants.h (contains both constants and test function definitions) • main.cpp (test program driver) • mydatafile.txt (input file for the test run) • Buffer Pool Output.txt – if your program is correct your output should look like this

Here is the BufferBlockADT.h

#ifndef BUFFERBLOCKADT_H
#define   BUFFERBLOCKADT_H

#include <iostream>
#include <string>

using namespace std;

class BufferblockADT {
private:
//Instance variables:
   //   int blockID;
   //   char* block;
  
public:
  
   //sz is the size of the character array data
   //points to.
   BufferblockADT() {}
BufferblockADT(char* data, int sz = 4096) {}
   virtual ~BufferblockADT() {}
  
//read the block from pos to pos + sz-1 (or to the end of the block)
virtual void getData(int pos, int sz, char* data) = 0;
  
//setID
virtual void setID(int id) = 0;
  
//getID
virtual int getID() const = 0;
  
//getBlocksize
virtual int getBlocksize() const = 0;

//return the block
virtual char* getBlock() const = 0;
  
//set the block
virtual void setBlock(char* blk) = 0;
};

Here is the bufferpoolADT.h

#ifndef BUFFERPOOLADT_H
#define   BUFFERPOOLADT_H

#include <string>
using namespace std;

// ADT for buffer pools using the message-passing style
class BufferPoolADT {
private:
   //The buffer pool consists of X number of buffer blocks
  
public:
//Constructor gets the filename of the file to be buffered,
   //opens the file, and instantiates poolSize buffer blocks by
   //reading the file and filling the blocks in order. When the constructor
   //is done the buffer pool blocks should be full with the beginning
   //contents of the input file.
   BufferPoolADT() {}
BufferPoolADT(string filename, int poolSize = 5, int blockSize = 4096) {}
virtual ~BufferPoolADT() {}
  
// Copy "sz" bytes from position "pos" of the buffered
// storage to "space".
virtual void getBytes(char* space, int sz, int pos) = 0;
  
   // Print the order of the buffer blocks using the block id
   //   numbers.
   virtual void printBufferBlockOrder() = 0;
  
   // Get the block id number of the least recently used
   //   buffer block.
   virtual int getLRUBlockID() = 0;
};

Here are the constants

#ifndef CONSTANTS_H
#define   CONSTANTS_H

#include <iostream>
using namespace std;

static const int BLOCKSIZE = 4096;   //buffer blocksize
static const int POOL_SIZE = 5;    //number of buffer block in the buffer pool

//common char functions
//create and initialize a char array and then return a pointer to it
void initializeCharArray(int sz, char* ch) {
for (int i=0; i<sz; i++) {
ch[i] = (char) NULL;
}
}

//get a new char array and initialize it
char* getCharArray(int sz) {
char* myChars = new char[sz];
initializeCharArray(sz, myChars);
return myChars;
}

//print out a string of chars
void printChars(char* ch, int sz, int blkid) {
cout << "My data for block " << blkid << " is: \"";
for (int i=0; i<sz; i++) {
cout << ch[i];
}
cout << "\"\n";
}

#endif   /* CONSTANTS_H */

Homework Answers

Answer #1

In the question given as block size is 4096 and pool size is 5

let f(n) is a function and stepf(n) is number of steps used to calculate f(n)

for n>8oo,f(n)= n-5

n>800 this is 1

now f(801) =796, stepsf(801)=1

f(800)=f(f(806))=f(801)=796,stepsf(800)=3

f(799)=f(f(805))=f(800)=796,steps(799)=5

thus stepsf(n)=stepsf(n+1)+2

stepsf(800)=3

stepsf(799)=5

stepsf(798)=7

so,steps(800-i)=3+i*2

so stepsf(n)=1601+(n-1)*2 =2n+1599 for n<=>

and stepsf(n)=1 for n>800

and f(n) 796 for n<=>

f(n)=n-5 for n>800

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using the C programming language implement Heapsort in the manner described in class. Here is some...
Using the C programming language implement Heapsort in the manner described in class. Here is some example code to use as a guideline. Remember, you need only implement the sort algorithm, both the comparison and main functions have been provided. /* * * after splitting this file into the five source files: * * srt.h, main.c, srtbubb.c, srtinsr.c, srtmerg.c * * compile using the command: * * gcc -std=c99 -DRAND -DPRNT -DTYPE=(float | double) -D(BUBB | HEAP | INSR |...
- implement the Stack ADT using the linked list approach. Use C++ program language #include "StackLinked.h"...
- implement the Stack ADT using the linked list approach. Use C++ program language #include "StackLinked.h" template StackLinked::StackLinked (int maxNumber) { } template StackLinked::StackLinked(const StackLinked& other) { } template StackLinked& StackLinked::operator=(const StackLinked& other) { } template StackLinked::~StackLinked() {    clear(); } template void StackLinked::push(const DataType& newDataItem) throw (logic_error) {    } template DataType StackLinked::pop() throw (logic_error) { } template void StackLinked::clear() {    StackNode* t;    while ( top != NULL)    {        t = top;       ...
Need to get the following output by Editing ChekingAccount.h ,ChekingAccount.cpp CheckingAccount Derived class CheckingAccount that inherits...
Need to get the following output by Editing ChekingAccount.h ,ChekingAccount.cpp CheckingAccount Derived class CheckingAccount that inherits from base class Account and include an additional data member of type double that represents the fee charged per transaction (transactionFee). Write Checking- Account’s constructor that receives the initial balance, as well as a parameter indicating a transaction fee amount. If transaction fee is less than zero, the transactionFee will be set to zero. Write the chargeFee member function that updates the balance by...
Please provide answer in the format that I provided, thank you Write a program that prompts...
Please provide answer in the format that I provided, thank you Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is up to you as long as you implement some form of inheritance. Below is my code however the credit and the actual menu isn't working. Can i get some help on getting the menu to work properly. // BankAccount.h #ifndef ACCOUNT_H #define ACCOUNT_H #include <string> #include <iostream> using namespace std; class BankAccount { protected : int noOfWithdrawls; private: // Declaring variables    float balance;...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's algorithm to ensure mutual exclusion in the respective critical sections of the two processes, and thereby eliminate the race condition. In order to implement Peterson's Algorithm, the two processes should share a boolean array calledflagwith two components and an integer variable called turn, all initialized suitably. We will create and access these shared variables using UNIX system calls relating to shared memory – shmget,...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 565 Error 2 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 761 I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!! #include #include #include #include using namespace std; enum contactGroupType {// used in extPersonType FAMILY, FRIEND, BUSINESS, UNFILLED }; class addressType { private:...
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT