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.

Reply via email to