Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m making a program that simulates the C heap manager which is to allocate and

ID: 3668278 • Letter: I

Question

I'm making a program that simulates the C heap manager which is to allocate and deallocate dynamic memory. I have already finished all the functions except two:

void MemoryManager::free(unsigned char *blockptr)
// makes the block represented by the blocknode free
// and merges with successor, if it is free; also
// merges with the predecessor, it it is free

AND

void MemoryManager::mergeForward(blocknode *p)
// merges two consecutive free blocks
// using a pointer to the first blocknode;
// following blocknode is deleted

Here are the 2 header files:

struct blocknode
{
unsigned int bsize;
bool free;
unsigned char *bptr;
blocknode *next;
blocknode *prev;

blocknode(unsigned int sz,unsigned char *b,bool f=true,blocknode *p=0,blocknode *n=0):
   bsize(sz),free(f),bptr(b),prev(p),next(n) {}
};

AND

class MemoryManager
{
public:
MemoryManager(unsigned int memsize);
unsigned char * malloc(unsigned int request);
void free(unsigned char * blockptr);
blocknode *getFirstPtr();
friend ostream & operator<<(ostream & out,const MemoryManager &M);

private:
unsigned int memsize;
unsigned char *baseptr;
blocknode * firstBlock;

void mergeForward(blocknode *p);
void splitBlock(blocknode *p,unsigned int chunksize);
};
  

Explanation / Answer

#include __declspec(target(mic)) float *fp[10]; __declspec(target(mic)) float *fp0; int main() { int i; // Allocate memory and initialize for (i=0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote