ent 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 Your Buffer Block must inherit BufferBlockADT or you will not get credit for your work. All BufferBlockADT virtual functions mus

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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
    • 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 bytes
  • 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 
  • 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.

 

/* Assuming you initialize your buffer pool with blocks 0-4 and
* open the test file as a binary file, your output for the first
* three tests (file position 5030, 16500, and 24640) should look
* 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,

My data for block 4 is: "e for the "
My buffer block order from most recently used to LRU is:
4, 1, 0, 2, 3,

My data for block 6 is: "ent a Buff"
My buffer block order from most recently used to LRU is:
6, 4, 1, 0, 2,

E#include "constants.h"
#include "LRUBufferPool.h"
using namespace std;
Bint 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 ();
/*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,
//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->printBufferBlockorder ();
/*Output should be something like the following:
My data for block 4 is: "e for the
My buffer block order from most recently used to LRU is:
4, 1, 0, 2, 3,
*/
//re-initialize the char array and get the next block of data
initializecharArray(10, data);
bp->getBytes (data, 10, 24640);
printchars(data, 10, 24640/BLOCKSIZE);
bp- >printBufferBlockorder();
/*Output should be something like the following:
My data for block 6 is: "ent a Buff"
My buffer block order from most recently used to LRU is:
6, 4, 1, 0, 2,
* /
//re-initialize the char array and get the next block of data
initializecharArray(10, data);
bp->getBytes(data, 10, 28700);
printchars (data, 10, 28700/BLOCKSIZE);
bp->printBufferBlockOrder ();
//re-initialize the char array and get the next block of data
initializecharArray(10, data);
bp->getBytes(data, 10, 16600);
printchars(data, 10, 16600/BLOCKSIZE);
bp->printBufferBlockOrder ();
//close program
cout <« endl << endl;
system("pause");
return 0;
Transcribed Image Text:E#include "constants.h" #include "LRUBufferPool.h" using namespace std; Bint 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 (); /*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, //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->printBufferBlockorder (); /*Output should be something like the following: My data for block 4 is: "e for the My buffer block order from most recently used to LRU is: 4, 1, 0, 2, 3, */ //re-initialize the char array and get the next block of data initializecharArray(10, data); bp->getBytes (data, 10, 24640); printchars(data, 10, 24640/BLOCKSIZE); bp- >printBufferBlockorder(); /*Output should be something like the following: My data for block 6 is: "ent a Buff" My buffer block order from most recently used to LRU is: 6, 4, 1, 0, 2, * / //re-initialize the char array and get the next block of data initializecharArray(10, data); bp->getBytes(data, 10, 28700); printchars (data, 10, 28700/BLOCKSIZE); bp->printBufferBlockOrder (); //re-initialize the char array and get the next block of data initializecharArray(10, data); bp->getBytes(data, 10, 16600); printchars(data, 10, 16600/BLOCKSIZE); bp->printBufferBlockOrder (); //close program cout <« endl << endl; system("pause"); return 0;
#ifndef BUFFERPOOLADT H
#define BUFFERPOOLADT H
tinclude <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.
//is done the buffer pool blocks should be full with the beginning
//contents of the input file.
BufferPoolADT() {}
When the constructor
4096) {}
BufferPoolADT (string filename, int poolSize
virtual ~BufferPoolADT() {}
5, int blockSize
// Copy "sz." bytes from position "pos" of the buffered
//
virtual void getBytes(char* space, int sz,
storage to "space".
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;
tendif
/* BUFFERPOOLADT.H */
Transcribed Image Text:#ifndef BUFFERPOOLADT H #define BUFFERPOOLADT H tinclude <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. //is done the buffer pool blocks should be full with the beginning //contents of the input file. BufferPoolADT() {} When the constructor 4096) {} BufferPoolADT (string filename, int poolSize virtual ~BufferPoolADT() {} 5, int blockSize // Copy "sz." bytes from position "pos" of the buffered // virtual void getBytes(char* space, int sz, storage to "space". 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; tendif /* BUFFERPOOLADT.H */
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

How do you implement the BufferBlock class and the LRUBufferPool class?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Software Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education