Reference Counting Template

dsimcha dsimcha at yahoo.com
Mon Dec 14 06:57:05 PST 2009


== Quote from Lutger (lutger.blijdestijn at gmail.com)'s article
> What are you planning to with multithreading?
> With the current type system, is it possible to statically detect inside the
> template if the refcount is used in shared scenario's, and base the
> implementation on that information? That would be ideal, if it is indeed
> possible.

I was thinking just make all increments and decrements of the reference count
field atomic.  x86 and probably most other architectures have an atomic increment
and atomic decrement snippet.  If the full semantics of shared get implemented,
I'll reconsider.

> std.stdio.File is refcounted, perhaps you can see to replace it's
> implementation with your template.
> Thanks you for this, I think it's great that D will have it out-of-the-box.

Yeah, that's what gave me the idea.  That and working with very large data
structures for which false pointers and slow GC times bite hard, and I'd rather
allocate on the C heap and delete deterministically.

> Managing resources in say C# or Java is a pain in the wrist.

Yeah, good GC is part of the answer, but I don't understand why they don't even
attempt to make it easy to manage other resources.  Finally blocks are basically
an invitation to write tons of boilerplate code.



More information about the Digitalmars-d mailing list