If T[new] is the container for T[], then what is the container for T[U]?

Michel Fortin michel.fortin at michelf.com
Sun Apr 26 06:11:17 PDT 2009


On 2009-04-25 19:44:18 -0400, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

> There are three schemes that are good starting points:
> 
> 1. As right now :o).
> 
> 2. Using refcounting. Arrays will be 4 words long (begin, end, 
> end-of-store, refcount*) and slices will be 3 words long (begin, end, 
> and owner*)
> 
> 3. Using manual management. Arrays will be 3 words long (begin, end, 
> end-of-store) and slices will be 2 words long (begin, end). This is 
> close to C++/STL. This case is less safe but very efficient.
> 
> If we manage to integrate them all... that's quite the holy grail. And 
> I think it's entirely possible with only a few changes to the language.

1 and 2 certainly look useful.

I've never found 3 to be efficient in the C++/STL. Making a copy every 
time you need to store a string in a struct isn't something I call 
efficient. Especially in a language that supports immutable strings, 
reference counting seems immencely preferable. And reference counting 
has the advantage that it does not require any change or addition to 
the language syntax or semantics.

Andrei, do you have a use case for 3 that would end up worse using 
reference counting? Because I only see appending, and even then, 
appending when the refcount is 1 could be done in-place which would be 
pretty efficient.


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list