Relaxing the definition of isSomeString and isNarrowString
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Sun Aug 24 10:59:46 PDT 2014
On 8/24/14, 6:16 AM, Dmitry Olshansky wrote:
> 24-Aug-2014 16:24, Andrei Alexandrescu пишет:
>> (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.)
>>
>
> The rest of post is mostly in line with my reasoning (except for nobody
> measures stuff, it's just bullshit).
Apologies for that, thanks for setting me straight.
> Speaking of data-structures I find just about the opposite. Most data
> structure are small, which must be the fact so fondly used by C++
> vector: small-string optimization. Only very few data-structures are
> large in a given program, and usually correspond to some global tables
> and repositories. Others are either short lived byproduct of input
> processing or are small data-sets attached to some global entity.
I don't know of any std::vector that uses the small string optimization.
std::string does ubiquitously because (a) strings are often handled as
values, and (b) C++11 put refcounted strings into illegality (forced
mistake) therefore robbing implementers of an important optimization.
In a way both C++ and D got it "wrong". Arrays/containers are entity
types - they have identity and should be manipulated most often by
reference. Presence of pass-by-value of containers in C++ programs, save
for rvalue optimization purposes, is suspicious. In contrast, strings
are value types - they are handled most often as a unit and passed by
value, just like e.g. numbers.
C++ made both containers and strings value types, so it needs forever to
look over its shoulder about n00bs copying large containers unwittingly.
It also does a fair amount of unneeded string copying, and optimizing
string-based C++ code is nontrivial. D made both arrays and strings
slices, a data structure made highly expressive by the garbage collector
but that occasionally confuses people. With std.refcounted.RCString and
std.container.Array we get both abstractions "right".
Andrei
More information about the Digitalmars-d
mailing list