Why same pointer type for GC and manual memory?
IGotD-
nise at nise.com
Wed Nov 13 16:43:27 UTC 2019
On Wednesday, 13 November 2019 at 15:30:33 UTC, Dukc wrote:
>
> I'm not 100% sure what managed pointers mean -Are they so that
> you can't pass them to unregistered memory? A library solution
> would likely do -wrap the pointer in a struct and make it
> @system to extract it's pointer as "raw". So you cannot put it
> to C-allocated arrays without type casting, which you probably
> don't do accidently.
>
Best example is probably managed C++, an MS extension to C++
which is now deprecated. However, it server as an interesting
example where MS extended C++ with a ^gc type.
https://en.wikipedia.org/wiki/Managed_Extensions_for_C%2B%2B
The ^gc type can actually be anything, raw pointer, reference
counted or any fat pointer of choice. The benefit with this is
that it doesn't intrude on C++ classical raw pointers, they are
kept the same without any restrictions. GC algorithm is easily
swappable like with Nim.
The D class is sort of a fat pointer but it only applies for
classes, it would be nice to extend this to any memory as well
(Yes you can GC allocate anything but then you get a raw pointer
without the type distinction that it is a GC allocated object).
More information about the Digitalmars-d-learn
mailing list