Garbage collected pointers?
rikki cattermole
rikki at cattermole.co.nz
Thu Mar 1 10:13:48 UTC 2018
On 01/03/2018 11:10 PM, 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.
>
> My question is how do I tell if a pointer is "garbage collected" or not?
>
> For example :-
> * Do not store magic values into pointers, other than null.
>
> So how do I tell if it's safe to do this for any individual pointer?
> What makes a pointer "garbage collected"?
You cannot tell if a random pointer is owned by the GC or not.
If a piece of memory is allocated not by the GC in your own function,
that's fairly easy. You'll know about it thanks to calling e.g. malloc
versus new or .length.
More information about the Digitalmars-d-learn
mailing list