Garbage collected pointers?

Dmitry Olshansky dmitry.olsh at gmail.com
Thu Mar 1 11:04:41 UTC 2018


On Thursday, 1 March 2018 at 10:10:27 UTC, John Burton wrote:
> In the language spec here :-
> https://dlang.org/spec/garbage.html#pointers_and_gc
>
> It refers to a distinction between pointers to garbage 
> collected memory and pointers that are not. In particular it 
> says that with a non garbage collected pointer you can do 
> anything  that is legal in C but with a garbage collected 
> pointer there are a lot of undefined behaviors if you don't 
> follow some restrictions.

Basically you can do whatever you want with pointers, you may 
twart ability of GC to free an object b/c you constructed some 
value that points to GC heap. That’s pretty much it.

Second side is loosing pointers to GC owned object, this happens 
when you put pointers into eg malloced chunk of memory.

Calling GC.addRange/removeRange you can let GC know that you 
stored pointers to GC heap in some place other then stack or GC 
heap.





More information about the Digitalmars-d-learn mailing list