Find the best answers to your questions with the help of IDNLearn.com's knowledgeable users. Ask your questions and receive reliable and comprehensive answers from our dedicated community of professionals.

Consider an allocator on a 32-bit system that uses an implicit free list. Each memory block, either allocated or free, has a size that is a multiple of four bytes. Thus, only the 30 higher order bits in the header and footer are needed to record block size, which includes the header and footer and is represented in units of bytes. The usage of the remaining 2 lower order bits is as follows: bit 0 indicates the use of the current block: 1 for allocated, 0 for free. bit 1 indicates the use of the previous adjacent block: 1 for allocated, 0 for free Below is a helper routine defined to facilitate the implementation of free (void *P). Which option, if any, will complete the routine so that it performs the function properly?\
Note: "size" in the answers indicates the size of the entire block /* given a pointer to a valid block header or footer, returns the size of the block */
int size(void *hp)
{
int result;
__________;
return result;
}
1. result=(*(int *)hp)&(-7)
2. result=((*(char *)hp)&(-5))<<2
3. result=(*(int *)hp)&(-3)
4. result=(*hp)&(-7)
5. None of these


Sagot :

Answer:

result=(*(int *)hp)&(-3)

Explanation:

The result above would release the pointer or address of the integer data type with 3 memory blocks needed by the allocator.

We appreciate your contributions to this forum. Don't forget to check back for the latest answers. Keep asking, answering, and sharing useful information. IDNLearn.com has the solutions to your questions. Thanks for stopping by, and come back for more insightful information.