Why same pointer type for GC and manual memory?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Nov 13 12:03:05 UTC 2019


On Wednesday, 13 November 2019 at 11:07:12 UTC, IGotD- wrote:
> I'm trying to find the rationale why GC pointers (should be 
> names managed pointers) are using the exact same type as any 
> other pointer.

I assume you mean a GC that scans (not ref counting). GC pointers 
only need to be protected from being released, so regular 
"borrowing" pointers would be ok. That ought to be the most 
common pointer type in function signatures.

But then you would need a concept of "raw" pointers and "owning" 
pointers in addition.

> Doesn't this confusion make GC pointers just as unsafe as raw 
> pointers?

Only if it can be freed or if you can construct a pointer from 
integers so that pointers can be hidden when GC scans memory. 
Which is a reason for why high level GC languages treat 
pointers/references in an abstract way (no address information 
available).


> Has there been any prior discussion about introducing managed 
> pointers in D?

Yes, there has been several discussions in the forums over the 
years.

One argument against would be that people would not be able to 
use libraries that used a specific pointer type. That could be 
solved by using templated pointers or using 
borrowed-pointer-types in interfaces.

Another argument against has been that it would create a 
combinatorial explosion when people try to mix different pointer 
types. It might lead to more object code bloat, but should not be 
deal breaking.



More information about the Digitalmars-d-learn mailing list