How can I provide garbage collection for an interpreted language implemented in C?

前端 未结 3 585
后悔当初
后悔当初 2021-01-20 04:28

If I were to implement a garbage collected interpreted language in C, how can I go about providing precise (i.e. not conservative) garbage collection without writing my own

3条回答
  •  情话喂你
    2021-01-20 05:31

    When implementing such a language, your interpreter needs to keep track of all objects in the program it's running, including knowledge of their types and what part of the data is a reference to other data. Then it's trivial for you to walk all the data and implement whatever sort of garbage collector you like. No bogus hacks like trying to determine where the C implementation's "heap"/"stack"/etc. are located or guessing at what might be a pointer is needed, because you're dealing exactly with the data whose structure you know.

提交回复
热议问题