Question: Implement a disk - based buffer pool class based on the LRU buffer pool replacement strategy.Implement a disk - based buffer pool class based on

Implement a disk-based buffer pool class based on the LRU buffer pool replacement strategy.Implement a disk-based buffer pool class based on the LRU buffer pool replacement strategy.
This assignment comes from Project 8.3 on page 308 of your text. Using the supp
This assignment comes from Project 8.3 on page 308 of your text. Using the supplied C++ files to implement an LRU Buffer Pool. I have made the following changes to Project 8.3:
Implement a BufferBlock class using the supplied BufferBlockADT.h
Your Buffer Block must inherit BufferBlockADT or you will not get credit for your work.
All BufferBlockADT virtual functions must be implemented in BufferBlock
Block Size: 4096
The book says you have to use the first 4 bytes of the buffer block to store the block ID. I do not require that. You may 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 BufferPoolADTs functions (if you do not inherit BufferPoolADT you will not get credit for your work).
Your buffer pool should consist of 5 buffer blocks
Your buffer pool should manage the buffers using the LRU strategy
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)
CODE
BufferBlockADT.h
#ifndef BUFFERBLOCKADT_H
#define BUFFERBLOCKADT_H
#include
#include
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;
};
#endif /* BUFFERBLOCKADT_H */
BufferPoolADT.h
#ifndef BUFFERPOOLADT_H
#define BUFFERPOOLADT_H
#include
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;
};
#endif /* BUFFERPOOLADT_H */
Constants.h
#ifndef CONSTANTS_H
#define CONSTANTS_H
#include
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 <<"\"
";
}
#endif /* CONSTANTS_H */
Main.cpp
#include "constants.h"
#include "BufferPool.h"
using namespace std;
int main(){
//initialize buffer pool
LRUBufferPool* bp = new LRUBufferPool("mydatafile.txt", POOL_SIZE, BLOCKSIZE);
//get data from the buffer
char* data = new char[10];
bp->getBytes(data,10,5030);
printChars(data,10,5030/ BLOCKSIZE);
bp->printBufferBlockOrder();
cout << "LRU Buffer is "<< bp->getLRUBlockID()<< endl << endl;
/*
Output should be something like the following:
My data for block 1 is: "ment all o"
My buffer block order from most recently used to LRU is:
1,0,2,3,4,
LRU Buffer is 4
*/
//re-initialize the char array and get the next block of data
initializeCharArray(10, data);
bp->getBytes(data,10,16500);
printChars(data,10,16500/ BLOCKSIZE);
bp->p

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!