Jesse Phillips wrote: >I don't really think stdio is the place to see modern D ref counting. >The container class has an Array which is built to use RefCounted. I >had tried my and at explaining how to use it: http://stackoverflow.com/ >questions/4632355/making-a-reference-counted-object-in-d-using- >refcountedt/4635050#4635050 > >I'm not really sure if all the details have been worked out. Hopefully >I explained it correctly and that it gives you an idea of how to make >ref counting work.
Thanks, I think I understand how to use RefCounted now. But it still leaves this issue: Is it possible to add explicit de-referencing to allow a global struct / struct in class to be manually dereferenced? And it adds a new one: RefCounted calls addRange https://github.com/D-Programming-Language/phobos/blob/master/std/typecons.d#L2304 if the _store size is >= size_t (In fact, as _store already has a size_t for count, addRange will always get called?). This means even if I only want RefCounting for a simple C handle, addRange will be called. I don't understand the use of malloc & free in RefCounted. If addRange is called anyway, why not just use GC.malloc and GC.free? One more thing: The removeRange call uses a different condition: if (hasIndirections!T && RefCounted._store) GC.removeRange(RefCounted._store); if (sz >= size_t.sizeof && p.ptr) GC.addRange(p.ptr, sz); Now say, I store a single byte, wouldn't addRange get called but removeRange not? -- Johannes Pfau