Question
A question in data structuers and algorithms For example, in order for a garbage collector to be able to keep track of memory usage, you
A question in data structuers and algorithms
For example, in order for a garbage collector to be able to keep track of memory usage, you need to keep track of how many and which references there are for each allocated memory area. In the most common and simplest case, there is only one pointer / reference that refers to a certain area, but there is no upper limit for how many pointers / references can be allowed to reference there.
Implement a data structure in C that represents smart pointers. The features that must be included are:
* alloc: int --> ref (Assigns memory of a certain size and returns reference there)
* assign: ref --> ref (The outer reference refers to the same thing as the inner reference)
* free: ref --> ref (the reference points to NULL / nil afterwards)
* gc: 0 --> 0 (Free up memory that is no longer referred to)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started