Commit 8b3a0d24 authored by Son Pham's avatar Son Pham

Lab 8.1 Completed

parent e0608595
Name: Son Pham
Class: CSCI 208
Prof: Luiz Felipe Perrone
Lab 8 - answers.txt
Problem 1
1. Segmentation fault occurs when a process tries to access a memory address that is outside of boundary of the physical page that the process incapsulates.
2. Doubly linked list has a lot of advantage is this kind of problems. It creates:
+ O(n) in space complexity. You only need 3 piece of information for each process.
+ Since each node only needs a pointer to link to other, the list can be stored virtually anywhere as long as the 3 pieces of information stay intached. Other data structure such as array requires spatial locality.
+ O(1) in allocation, adding a new node to a linked list is very easy and takes almost no effort, and a linked list doesn't need a specific bound. In contrast, an array may need an O(n) algorithm to double its size.
+ O(n) access time, you will have to traverse the whole list to find out where it is.
With a lot of benefits from doubly linked list and acceptable access time. This data structure is ideal for the problem.
3. malloc is a general-purpose memory allocated. It adds a "memory node" in the allocated list and allocate the amount of memory specified into that node. The memory in the free list decrease
Free basically grab a node from allocated list and add the same node back to the free list.
Doubly-linked list is a very suitable data structure for this problem due to equal-or-faster-than-linear run time for all operation and no requirement for spatial locality.
A Heap structure can also be very good if the user specifically want either best-fit or worst-fit as it is sligtly more efficient in adding node with O(log n) time. However, compacting node in Heap requires O(n log n) time and the benifit doesn't worth the cost as the memory has to compact very regularly.
4. External fragmentation is a piece of memory OUTSIDE of the process that contains no meaningful data in it.
5. Internal fragmentation is a piece of memory INSIDE of the process that contains no meaninful data. This is due to the fact that the process doesn't occupy the whole memory page to store it data, leaving some internal residue.
6. First-fit: Go to the first memory blob available and has enough capacity and allocate memory in the frame. This is obvious the most efficient in terms of allocating speed since it requires the least traversal. However, we have no control whether the allocation is good or bad.
7. Best-fit: Go to the smallest memory blob that still has enough memory to hold the process. It will try to make the best use of small piece of memory so that big piece of memory will be available for memory-intesive process. However, it leaves a lot of small residue.
8. Worst-fit: Go to the biggest memory blob possible and allocate a chunk to the process. This has the effect of "average out" the amount of memory available at each chunk and reduce the amount of small residue. However, this will not leave a lot of room for big process.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment