Relaxing the definition of isSomeString and isNarrowString

monarch_dodra via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 25 13:35:21 PDT 2014


On Sunday, 24 August 2014 at 12:24:03 UTC, Andrei Alexandrescu 
wrote:
> To that end I'm working on RCString, an industrial-strength 
> string type that's much like string, just reference counted and 
> with configurable allocation. It's safe, too - user code cannot 
> casually extract references to string internals. By default 
> allocation would use GC's primitives; one thing I learned to 
> appreciate about our GC is its ability to free memory 
> explicitly, which means RCString will free memory 
> deterministically most of the time, yet if you leak some (e.g. 
> by having RCString class members) the GC will pick up the 
> litter. I think reference counting backed up by a GC that lifts 
> litter and cycles and is a modern, emergent pattern that D 
> could use to great effect.
>
> (Speaking of which: Some, but not all, types in std.container 
> use reference counting. One other great area of improvement 
> would be to guarantee that everything is std.container is 
> reference counted. Containers are the perfect candidate for 
> reference counting - they are typically large enough to make 
> the reference counting overhead negligible by comparison with 
> the typical work on them.)

One issue this proposal seems to forget (and it's a problem that 
transcends D), is that the GC does not finalize structs. Your RC 
proposal is fine and good for strings, because the individual 
chars don't have destructors. But unless we migrate *everything* 
to using RC, we'd still be leaking non-memory resources.

For example, "File" is reference counted, and I've seen people 
time and time again get had, because they use a "File[]". Oops. 
Imo, this is a big issue. Are there any plans to takle this 
problem?

Another issue we encounter a lot with reference type objects that 
do RC, is one of initial initialisation/allocation. Currenly, D 
does not have default constructor. I understand why. But it makes 
it painfainly difficult to implement run-time initialize with no 
arguments, while avoiding user errors. This has been a problem 
time and time again for objects such as Appender, or T[U], in 
that aliasing only happens *after* the first operation.

Has this been discussed again yet? We have "T.init". Why couldn't 
we have default construction, that can be explicitly skipped with 
"T a = T.init;"?

I realize this derails the conversation a bit, but I think it is 
related enought to warrant mentioning.


More information about the Digitalmars-d mailing list