Question

In: Computer Science

How do we end up creating garbage cells? Give example C++ code. What does garbage collection...

  1. How do we end up creating garbage cells? Give example C++ code.
  2. What does garbage collection do? Be specific.
  3. Why is it good to use a reference counter in GC? Two advantages.[2]
  4. Name a way to avoid fragmentation in allocation of different sizes.

Solutions

Expert Solution

1. How we end up creating garbage cells? Give example C++ code.

Answer :  If an object is created in C++ but is not destroyed before it goes out of scope, then we end up creating something known as garbage cell. For example, we have a pointer pointing to a particular varibal,e however, that variable becomes out of scope, that pointer becomes eligible for Garbage cell.

Example :

{

char *ptr = NULL;

{

char c;

ptr = &c;

}

// Now c is out of scope, thus ptr becomes eligible for Garbage collection.

}

2. What does garbage collection do?

Answer : Garbage Collection is a type of automatic memory management. It tries to collect and reclaim that garbage which won't be used again in the program.

Ususally, we store a program in two ways: Stack or heap.

The dynamically allocated variables inside a program are stored in a heap. Which by default has unlimited acces means it never gets deleted. However, that would lead to filling of memory soon. Thus, there is something known as Garbage collection that does this task for you automatically. We don't have to manage manually the memory, GC does it for us automatically.

3. Advantage to use a reference counter in GC?

Answer : Using reference counter in GC has a lot of advantages like:

- Objects can be reclaimed as soon as they become eligible for garbage collection and that too in an incremental manner and without any delay.

- Reference counter is useful for realtime performance in GC. Thus, it gives a more consistent performance with no pauses,

4. two ways to avoid fragmentation in allocation of different sizes.:

- Compaction is the tchnique used to avoid fragmentation.

- Copying Garbage Collection : A copying garbage collector compacts the heap to eliminate unused space completely.

This way fragmentation can be avoided.

Hope it helps!

Please upvote if you like it!

Thank you:)


Related Solutions

How do I write a C# and a C++ code for creating a character array containing...
How do I write a C# and a C++ code for creating a character array containing the characters 'p', 'i', 'n','e','P','I','N','E' only and then using these lower and capital case letter character generate all possible combinations like PInE or PinE or PIne or PINE or piNE etc. and only in this order so if this order is created eg. NeIP or EnPi or NeIP or IPnE and on. You can generate all the combinations randomly by creating the word pine...
give a description of how vaccines work. What do we inject and how does this give...
give a description of how vaccines work. What do we inject and how does this give us immunity? Be specific about how the cells work.
How does a patient end up with excess fluid in their body? What do they look...
How does a patient end up with excess fluid in their body? What do they look like? How are their organs affected? What are the common treatments for fluid excess?
2. What do we mean by the term substantive analytical procedures? Give an example of how...
2. What do we mean by the term substantive analytical procedures? Give an example of how an auditor would perform an analytical procedure for acquisitions? 3. What substantive analytical procedures might an auditor use to perform an analytical procedure for accounts payable?
What is a worm, what does it do, and how does it propagate? Provide an example...
What is a worm, what does it do, and how does it propagate? Provide an example of a well-known worm. Write about 500 words and sources
What two layers make up the skin? What do we call the pigment-producing cells in our...
What two layers make up the skin? What do we call the pigment-producing cells in our skin? List the five different strata of cells found in thick skin. Which layer contains cells that are dividing? Which layer is thickest? What type of protein fibers are present in the dermis? The hypodermis is primarily composed of what type of tissue? Identify ONE (1) way in which hair and nails are similar and ONE (1) way in which they differ. What role...
For acid woke up, when do we use H2O or H3O+. Please give example. Thank you.
For acid woke up, when do we use H2O or H3O+. Please give example. Thank you.
Question: How can data collection for diseases be improved? What tools do we need? What are...
Question: How can data collection for diseases be improved? What tools do we need? What are medical intelligence and syndromic surveillance, and how are they used or how could they be used?
Give an example of one of the ways we can empirically measure agglomeration. What does that...
Give an example of one of the ways we can empirically measure agglomeration. What does that measure tell us, and why might it be problematic?
4. Give an example of one of the ways we can empirically measure agglomeration. What does...
4. Give an example of one of the ways we can empirically measure agglomeration. What does that measure tell us, and why might it be problematic?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT