Welcome to Westonci.ca, where you can find answers to all your questions from a community of experienced professionals. Get quick and reliable solutions to your questions from a community of seasoned experts on our user-friendly platform. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.

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.