please continue this function only // Utilities for malloc blocknode * MemoryMan
ID: 3905134 • Letter: P
Question
please continue this function only
// Utilities for malloc
blocknode *
MemoryManager::findFirstFit (unsigned int chunksize)
{
// returns a pointer to the first blocknode whose blocksize is at least chunksize;
// if there is no such blocknode, returns nullptr
here is the memoryManager.h
MemoryManager.h class MemoryManager public: MemoryManager(unsigned int memtotal); unsigned char malloc(unsigned int request); void free(unsigned char * ptr2block); void showBlockList); MemoryManager.h private: blocknode *header; blocknode *trailer; unsigned int memsize; II heap size unsigned char *basepu; // pointer to first byte of heap //utilities for malloc method: blocknode*findFirstFit(unsigned int chunksize); void splitBlock(blocknode *p,unsigned int chunksize); //utilities for free method blocknode *findAllocatedBlock (unsigned char *allocated ptr); void mergeForward(blocknode *p); void mergeBackward(blocknode *p);Explanation / Answer
blocknode * MemoryManager::findFirstFit (unsigned int chunksize){
blocknode *p = header;
while (p != NULL && p->blocksize < chunksize){
p = p->next;
}
return p;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.