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 |...
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:...
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...
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...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
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....
I'm not sure how to fix my code I keep getting an error with rhs.begin. I...
I'm not sure how to fix my code I keep getting an error with rhs.begin. I linked the header file and the test file, THESE TWO CANNOT be changed they have absolutely no errors in them. To clarify I ONLY need help with the copy constructor part. /* ~~~~~~~~~~~~list.cpp~~~~~~~~~~~~~~~*/ #include #include "list.h" using namespace std; Node::Node(string element) { data = element; previous = nullptr; next = nullptr; } List::List() { first = nullptr; last = nullptr; } List::List(const List& rhs)//...
You are asked to implement a C++ class to model a sorted array of unsigned integers....
You are asked to implement a C++ class to model a sorted array of unsigned integers. The class is to be used in an embedded application that cannot assume the presence of the STL. The array has to be dynamically allocated in such a way that allows programmers using it to specify the required size. Your class should should: (1) provide the appropriate constructors and destructor; (2) provide methods for updating, and showing numbers in/to the array (e.g., to be...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private data member for the triplet is a generic array with three elements. The triplet ADT has the following functions:  default constructor  explicit constructor: initialize the data member using parameters  three accessors (three get functions) which will return the value of each individual element of the array data member  one mutator (set function) which will assign values to the data member...