Question: please help, i am comfused on how to implement this in c using brk and sbrk. how exactly should i be using the character pointers?

please help, i am comfused on how to implement this in c using brk and sbrk. how exactly should i be using the character pointers? thank you  please help, i am comfused on how to implement this in
c using brk and sbrk. how exactly should i be using the

Exercise: Write a memory simulation with malloc() and free() Howto: //Have a global array of one MB unsigned char myheap [1048576); 7/Have a pagesize #define PAGESIZE 1024 //or 2048, or 4096 - This is your heap simulation (yes, its in the uninitialized space, but we are simulating the heap!). Right now, you have all the space free, that means one big chunk of free space. In general, every chunk of space should start with a chunk head: typedef struct chunkhead { unsigned int size; unsigned int info; unsigned char *next, *prev; }chunkhead; How much bytes are these? Remember later to add this to new-to-allocate memory! Obviously, you can set the first chunkhead to: size = 1048576 - sizeof(chunkhead); info = 0;//means its free space next = prev = 0; Write a malloc and a free function: unsigned char *mymalloc(unsigned int size); void myfree(unsigned char address); Also, write a code analysis function: void analyse(); mymalloc function (unsigned int size) This function should search in your list for a free chunk that is big enough for the requested memory (parameter size). It should return the address of the mem after the chunkhead. Change the chunkhead to be occupied (info=1), the correct size and the correct next chunkhead, in case you need to split the memory. Return NULL (0) if no chunk is big enough. Allow only multiples of PAGESIZE!! myfree function (unsigned char address) This function should sets the given chunk to "free", meaning info=0; if the previrous or next chunk is free as well, it should remove the chunk(s) and link both ends together. Don't remove the first one of such a chain though!! " optional, but necessary at program 2 analyse function This function should go through the list of chunks and print for every chunk its content of the structure. E.g.: (this is just a printing example, don't take the numbers serious) Chunk #1: Size = 1024 bytes //mockup number Occupied Next =0x23423434 //mockup number Prev = 0x00000000 Chunk #2: Size = 1047528 bytes //mockup number Free Next = 0x00000000 Prev = 0x2342ffa //mockup number If you have a better style in mind, its fine not to follow this printing style. Just have all information printed! How we test Please prepare your function for testing, by writing a void main with following body: unsigned char *a,"b,*c a = mymalloc(1000); b = mymalloc(1000); c = mymalloc(1000); myfree(b); myfree(a); analyse(); We will test your program with combinations of mymalloc() and myfree() and check with analyse() if everything is as it should. We will try to go to the mem limit! Exercise: Write a memory simulation with malloc() and free() Howto: //Have a global array of one MB unsigned char myheap [1048576); 7/Have a pagesize #define PAGESIZE 1024 //or 2048, or 4096 - This is your heap simulation (yes, its in the uninitialized space, but we are simulating the heap!). Right now, you have all the space free, that means one big chunk of free space. In general, every chunk of space should start with a chunk head: typedef struct chunkhead { unsigned int size; unsigned int info; unsigned char *next, *prev; }chunkhead; How much bytes are these? Remember later to add this to new-to-allocate memory! Obviously, you can set the first chunkhead to: size = 1048576 - sizeof(chunkhead); info = 0;//means its free space next = prev = 0; Write a malloc and a free function: unsigned char *mymalloc(unsigned int size); void myfree(unsigned char address); Also, write a code analysis function: void analyse(); mymalloc function (unsigned int size) This function should search in your list for a free chunk that is big enough for the requested memory (parameter size). It should return the address of the mem after the chunkhead. Change the chunkhead to be occupied (info=1), the correct size and the correct next chunkhead, in case you need to split the memory. Return NULL (0) if no chunk is big enough. Allow only multiples of PAGESIZE!! myfree function (unsigned char address) This function should sets the given chunk to "free", meaning info=0; if the previrous or next chunk is free as well, it should remove the chunk(s) and link both ends together. Don't remove the first one of such a chain though!! " optional, but necessary at program 2 analyse function This function should go through the list of chunks and print for every chunk its content of the structure. E.g.: (this is just a printing example, don't take the numbers serious) Chunk #1: Size = 1024 bytes //mockup number Occupied Next =0x23423434 //mockup number Prev = 0x00000000 Chunk #2: Size = 1047528 bytes //mockup number Free Next = 0x00000000 Prev = 0x2342ffa //mockup number If you have a better style in mind, its fine not to follow this printing style. Just have all information printed! How we test Please prepare your function for testing, by writing a void main with following body: unsigned char *a,"b,*c a = mymalloc(1000); b = mymalloc(1000); c = mymalloc(1000); myfree(b); myfree(a); analyse(); We will test your program with combinations of mymalloc() and myfree() and check with analyse() if everything is as it should. We will try to go to the mem limit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!