February 13, 2015 Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Per Nordlöw | On Friday, 13 February 2015 at 12:58:40 UTC, Per Nordlöw wrote: > On Friday, 13 February 2015 at 12:50:14 UTC, Tobias Pankrath wrote: >> There are no reference counts involved, just simple arithmetic. >> >> string a = "abc"; >> string b = a[1 .. $]; > > Then how does the GC know when to release when there are multiple references? > > Is this because string references immutable storage? It scans the memory for pointers to the memory to be freed before freeing them. > Isn't vgc recursively inferred bottom-up for calls to templates functions? I didn't know vgc exists until your question, so I don't know what it does exactly. Thought that it will highlight calls to GC.malloc in the current function, even if emitted by the compiler for e.g. closures. I don't think it treats template functions different than other functions (it only considers their signature). |
February 13, 2015 Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Per Nordlöw | Per Nordlöw:
> Then how does the GC know when to release when there are multiple references?
The mark phase counts what's reachable and what can't be reached. If an object has one pointer to it, or one hundred pointers, it is not removed. If nothing points to it, it is removed.
I suggest you to read how a mark&sweep GC works, or better to implement a bare-bones mark&sweep GC in C language yourself for Lisp-like cons cells, you only need 100 lines of code or so to do it.
Bye,
bearophile
|
February 13, 2015 Re: Data-Flow (Escape) Analysis to Aid in Avoiding GC | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Friday, 13 February 2015 at 13:07:04 UTC, bearophile wrote:
> I suggest you to read how a mark&sweep GC works, or better to implement a bare-bones mark&sweep GC in C language yourself for Lisp-like cons cells, you only need 100 lines of code or so to do it.
Got it. Thanks.
|
Copyright © 1999-2021 by the D Language Foundation