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 diskbased buffer pool class based on the LRU buffer pool replacement strategy.Implement a diskbased buffer pool class based on the LRU buffer pool replacement strategy.
This assignment comes from Project on page of your text. Using the supp
This assignment comes from Project on page of your text. Using the supplied C files to implement an LRU Buffer Pool. I have made the following changes to Project :
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:
The book says you have to use the first 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; ieint blockID.
Implement a Buffer Pool by inheriting BufferPoolADT BufferPoolADTh 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 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 BUFFERBLOCKADTH
#define BUFFERBLOCKADTH
#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
BufferblockADTchar data, int sz
virtual ~BufferblockADT
read the block from pos to pos szor to the end of the block
virtual void getDataint pos, int sz char data;
setID
virtual void setIDint id;
getID
virtual int getID const ;
getBlocksize
virtual int getBlocksize const ;
return the block
virtual char getBlock const ;
set the block
virtual void setBlockchar blk;
;
#endif BUFFERBLOCKADTH
BufferPoolADT.h
#ifndef BUFFERPOOLADTH
#define BUFFERPOOLADTH
#include
using namespace std;
ADT for buffer pools using the messagepassing 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
BufferPoolADTstring filename, int poolSize int blockSize
virtual ~BufferPoolADT
Copy sz bytes from position "pos" of the buffered
storage to "space".
virtual void getByteschar space, int sz int pos;
Print the order of the buffer blocks using the block id
numbers.
virtual void printBufferBlockOrder;
Get the block id number of the least recently used
buffer block.
virtual int getLRUBlockID;
;
#endif BUFFERPOOLADTH
Constants.h
#ifndef CONSTANTSH
#define CONSTANTSH
#include
using namespace std;
static const int BLOCKSIZE ; buffer blocksize
static const int POOLSIZE ; 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 initializeCharArrayint sz char ch
for int i ; i sz; i
chicharNULL;
get a new char array and initialize it
char getCharArrayint sz
char myChars new charsz;
initializeCharArraysz myChars;
return myChars;
print out a string of chars
void printCharschar ch int sz int blkid
cout My data for block blkid is: ;
for int i ; i sz; i
cout chi;
cout
;
#endif CONSTANTSH
Main.cpp
#include "constants.h
#include "BufferPool.h
using namespace std;
int main
initialize buffer pool
LRUBufferPool bp new LRUBufferPoolmydatafiletxt POOLSIZE, BLOCKSIZE;
get data from the buffer
char data new char;
bpgetBytesdata;
printCharsdata BLOCKSIZE;
bpprintBufferBlockOrder;
cout "LRU Buffer is bpgetLRUBlockID endl endl;
Output should be something like the following:
My data for block is: "ment all o
My buffer block order from most recently used to LRU is:
LRU Buffer is
reinitialize the char array and get the next block of data
initializeCharArray data;
bpgetBytesdata;
printCharsdata BLOCKSIZE;
bpp
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
