Question

**C PROGRAM*** Q: Which of these changes will improve the memory utilization of a malloc implementation?...

**C PROGRAM***

Q: Which of these changes will improve the memory utilization of a malloc implementation?

1. Making the free function do nothing 2. Increasing the alignment requirement for objects 3. Changing from an implicit to an explicit free list 4. Adding footer boundary tags in addition to headers 5. Using a best-fit instead of a first-fit search

Q: It is possible to use garbage collection with C programs, but with this limitation:

1. The size of an object cannot be changed using realloc 2. The garbage collector must be called after every allocation 3. Garbage collection can't be mixed with explicit calls to free 4. The garbage collector cannot relocate objects 5. All memory allocation must happen at the start of execution

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Q1.

Option 1: The 'free()' function is a predefined function in C, which is used to de-allocate a memory. Suppose a memory block 'p' is need to be freed so that it can be reused later. In order to do so, we need to run the command 'free(p)'. So it seems that 'free()' is used to reuse the memory, so option 1 cannot improve malloc implementation (Dynamic Memory Allocation).

Option 2: Object alignment is defined as the required space needed by the CPU to save and deal with an object in memory. Typically default alignment of int is 4 bytes, double is 8 bytes, char is 1 byte. So increase in the alignment requirement for objects may occupy unnecessary extra unused space in memory. So it's also not a good choice.

Option 3: Let us think that the memory is a linked list (heap). Now in case of implicit memory allocation, all the free and occupied blocks in the memory are connected using pointers. In this case, the size of each block is stored and by traversing it we can find the next block and check whether it is free or not. A special bit is used to indicate whether the block is free or not and also the size is given. Since it contains both free and already occupied blocks in the memory, this method is inefficient.

free- occupied free- - occupied 3 114 2 1

In the above implicit memory allocation the size is given at the start of each block and also it is said whether the blocks are occupied or not. The links are among all the blocks from start (free block of size 3) to finish (occupied block of size 1).

But in case of explicit list, only the free blocks in the memory are connected (using pointers). So if we use explicit allocation we can find only the free blocks, and the allocation is done if the required space in which the allocation is to be done is found. So it is more time efficient.

free occupied - free- occupied

In the above explicit allocation, only free blocks are connected. So clearly it is more efficient.

So option 3 will improve memory utilization malloc implementation.

Option 4: In C programming, adding footer boundary tags in addition to headers does not improve dynamic memory allocation. So Option 4 cannot improve malloc implementation.

Option 5: In memory allocation, 'first fit' is the allocation technique where allocation is done in the first free block of memory, which is big enough for the required allocation (with respect to size). 'Best fit' allocation technique says that allocation is to be done in the smallest free block of memory, which is big enough for the required allocation (with respect to size). So it is clear that if we use 'best fit' technique rather than 'first fit', the allocation choice will be better and other free blocks can be used for future purpose.

So option 5 can inprove memory utilization of malloc implementation.

Q2.

Option 1: Realloc() function in C is used to resize a block of memory that has already been allocated. So it is basically use to resize a block. Since it can resize, it can change the size of an object. So option 1 is not true.

Option 2: Garbage collection is a process to reuse the unused blocks in memory. It is not mandatory to use garbage collector after every allocation (though garbage collection is done by function free() in C). If we still have available memory for our remaining program we do not need to call the garbage collector after every allocation. So it is not required to call garbage collector after every allocation. So option 2 is not true.

Option 3: Garbage collection is actually a concept supported in JAVA which is executed automatically. It does not actually exist in C. But free() funtion in C works equivalent to garbage collector in JAVA. Though they both perform the same work, but they are fundamentally different since garbage collector is called automatically or implicitly (in JAVA) but free() is needed to be called explicitly by the programmer (in C). So garbage collection can't be mixed with explicit calls to free. Option 3 is true.

Option 4: Garbage collector makes the unused memory available for use. It basically make the memory blocks reusable which are currently used by objects that are no longer in use. Later in this memory blocks, new objects can be allowed to be allocated. So garbage collector cannot relocate a object, rather it removes the object from the program. So option 4 is true.

Option 5: In dynamic memory allocation, memory can be allocated runtime. Memory allocation is not done during compile time. So all memory allocation does not need to be done before the start of execution. So option 5 is false.

Add a comment
Know the answer?
Add Answer to:
**C PROGRAM*** Q: Which of these changes will improve the memory utilization of a malloc implementation?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT