A memory allocation ADT Flashcards
for memory allocation ADT how is object memory maintianed in a buffer of generic memory
the buffer is declared as an array of bytes(unsigned char)
we allocate two buffers, one that is currently in use, the other for running our memory recovery (compaction or defragmentation) operation
What is used to keep track of objects that have been allocated? How does it work and how is a new item added?
Draw it.
A linkedlist:
- each node is a struct that contains all the required information about the allocated block
- we maintain a free memory index that points to the start of the unallocated portion of the array
- To request memory for an object, we reserve the next block of free memory from the buffer, and add a new item to the end of the linked list
What happens when a reference count for an object reaches 0? What happens to it’s memory
We simply remove it’s entry from the linked list.
Nothing happens to memory until the garbage collector actually runs
What causes memory fragmentation? Draw it.
As objects are created and then marked as garbage, the memory will become fragmented.
When is the garbage collect algorithm run?
when we no longer have enough free memory at the end of the array to satisfy a memory request.
How does this garbage collection work for our HW4 ADT?
Draw it.
- copying the physical memory and update their entries in the linked list
- also maintain a pointer to the buffer currently being used.