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 */
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
Get Answers For Free
Most questions answered within 1 hours.