Closed jessiyajoy closed 1 year ago
- Block type is already set when setting the header using setHeader(). There is no need to call setBlockType again.
- setHeader() also calls getBufferPtr() which in turn calls getBlock() which calls getFreeBuffer() (everytime since the block number corresponds to an unallocated block) which makes calling getFreeBuffer() in getFreeBlock() unnecessary.
is probably confusing.
The idea is that getFreeBlock() sets the header of the newly allocated (not yet buffered) block. This results in a call to getFreeBuffer() everytime. That's why calling getFreeBuffer() in getFreeBlock() is unnecessary
// Constructor 1
BlockBuffer::BlockBuffer(char blockType) {
// allocate a block on the disc and a buffer in memory to hold the new block of given type using getFreeBlock function.
int newBlockNum;
switch (blockType) {
case 'R':
newBlockNum = getFreeBlock(REC);
break;
case 'I':
newBlockNum = getFreeBlock(IND_INTERNAL);
break;
case 'L':
newBlockNum = getFreeBlock(IND_LEAF);
break;
default:
newBlockNum = FAILURE;
}
// set the blockNum field of the object to that of the allocated block number.
// TODO: what happens if disk full..note down
this->blockNum = newBlockNum;
}
Done
verified that the caller handles E_DISKFULL wherever the constructor is in use.