Exercise 6 - Task2

rolli
Neuling
Neuling
Beiträge: 2
Registriert: 19. Dez 2015 14:30

Exercise 6 - Task2

Beitrag von rolli » 2. Mär 2018 21:51

Hi,

I have a problem understanding the representation (and GC handling) of the store in Ex06-Task 2. In particular the store locations represented as numbers (location 2, 6, 8, 10, 12, 14).

IMHO the store looks as follows according to the description of the interpreter:

Code: Alles auswählen

[0] -> Num(10)
[1] -> Box(0)
[2] -> Box(0)
[3] -> Box(2)
[4] -> Num(11)
[5] -> Box(4)
[6] -> Box(4)
[7] -> Box(6)
[8] -> Box(0)
[9] -> Box(8)
[10] -> Box(6)
[11] -> Box(10)
[12] -> Box(10)
[13] -> Box(12)
[14] -> Box(10)
[15] -> Box(14)
The environment only contains the mapping 'res -> 15. If that is the starting point e.g. for the mark-and-sweep GC then the following elements should be left within the store:

Code: Alles auswählen

[0] -
[1] -
[2] -
[3] -
[4] -> Num(11)
[5] -
[6] -> Box(4)
[7] -
[8] -
[9] -
[10] -> Box(6)
[11] -
[12] -
[13] -
[14] -> Box(10)
[15] -> Box(14)
In the solution are far more elements but I don't quite get why. What is wrong with my approach (start from location 15 and keep all referenced values)?

Jannis
Mausschubser
Mausschubser
Beiträge: 63
Registriert: 15. Apr 2015 17:10

Re: Exercise 6 - Task2

Beitrag von Jannis » 3. Mär 2018 11:57

Disclaimer: I am not a tutor

I would say that your approach is correct. But you have to consider that the Id-lookup actually returns the object from the store. This means when we insert this object inside the NewBox case in the store, the store contains the same object twice (seen at location 1 and 2, both contain the same Box(0) object). This also means that when we mark one of these objects as reachable, the other entry in the store is marked as well because they point to the same object.

In the exercise, the "1" at location 2 in the store means that this is exactly the same object as the one at location 1 (so that one can see whether two values in the store are the same or only equal).

rolli
Neuling
Neuling
Beiträge: 2
Registriert: 19. Dez 2015 14:30

Re: Exercise 6 - Task2

Beitrag von rolli » 3. Mär 2018 13:51

Totally makes sense! Thanks for the clarification.

Antworten

Zurück zu „Archiv“