Re:Baby's First Garbage Collector
by MichaelGG on Monday December 09, 2013 @01:09PM
(#6875665)
You only use them via out/ref. Section 13.4.2 of the CLI spec says:
- Managed pointers can be passed as arguments, stored in local variables, and returned as values.
- Managed pointers cannot be stored in static variables, array elements, or fields of objects or value types.
So you're right, they have very limited scope as it'd be messy otherwise. It's my understanding that the JVM does not have pointers even at this level, hence Java can't do out/ref parameters. (Sure, tuples are a better way to handle many cases of out params, but sometimes a well chosen ref can really be nicer.)
I think C++ also uses the term "managed pointer" but not in the same technical sense (I think it just means reference.) Using "safe" C++/CLI generation limits the scope of pointers just like we'd expect.
- Managed pointers can be passed as arguments, stored in local variables, and returned as values.
- Managed pointers cannot be stored in static variables, array elements, or fields of objects or value types.
So you're right, they have very limited scope as it'd be messy otherwise. It's my understanding that the JVM does not have pointers even at this level, hence Java can't do out/ref parameters. (Sure, tuples are a better way to handle many cases of out params, but sometimes a well chosen ref can really be nicer.)
I think C++ also uses the term "managed pointer" but not in the same technical sense (I think it just means reference.) Using "safe" C++/CLI generation limits the scope of pointers just like we'd expect.