Sale!

COMP 322 Assignment 2: Exploring Dynamic Memory solved

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (4 votes)

In this assignment we will be enhancing the implementation of the first assignment by
using dynamic memory management and pointers. This has the advantage of dynamically
growing the size of datastore as the demand increases and also shrinking it dynamically
when the demand decreases (when we delete a store).
This approach is much more efficient than the one used in the first assignment. There is no
capacity cap like previously because we will be dynamically allocating as much memory as
we need (until we hit the system’s capacity in terms of RAM memory limit).
In this new implementation, each store is independent and may reside in totally different
remote parts of memory. However, we still need to keep track of where the stores are, so
we still need to maintain a linked list structure that we will be calling datastore. datastore
will hold pointers to all the stores that were being dynamically allocated. Each cell of
datastore is a structure holding multiple elements in it:
● The store’s ID: id
● The store’s size: ssize
● Pointer to the store’s elements in memory: store_data
● Pointer to the next element in datastore: next
In other words, datastore is a linked list where each element is holding information about
each store as well as the pointer to the store itself like described in the figure above.
2
Please reimplement all the questions from assignment 1. You should also be using the
same main() function provided in assignment 1 for testing. The same output is expected.
In this implementation, we don’t need to define extra arrays to hold store related data. This
information is now being held by the structure maintaining information about each store.
The other difference from the first assignment is that we won’t need to display the number
of remaining available elements in the store because it is irrelevant since the store can
extend dynamically to accommodate as many individual stores as needed. We can replace
this display by the number of total used store elements at each time.
Please note that 10 points will be given for code readability and quality of comments
provided.
3