A few thoughts on std.allocator

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Tue May 12 08:51:38 PDT 2015


On 5/10/15 6:51 AM, Michel Fortin wrote:
> On 2015-05-10 09:50:00 +0000, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> said:
>
>> 3. Thread-local vs. shared objects
>>
>> Currently in D it's legal to allocate memory in one thread and
>> deallocate it in another. (One simple way to look at it is casting to
>> shared.) This has a large performance cost that only benefits very few
>> actual cases.
>>
>> It follows that we need to change the notion that you first allocate
>> memory and then brand it as shared. The "will be shared" knowledge
>> must be present during allocation, and use different methods of
>> allocation for the two cases.
>
> Shared is implicit in the case of immutable. Think carefully: if you
> implement this and it has any efficiency benefit for non-shared
> allocations, const-allocated objects and arrays will become more
> performant than immutable-allocated ones. People will thus have an
> incentive to stay away from immutable.
>

The whole concept of immutable being implicitly shareable is kind of 
broken. There are many reasons to have immutable unshared data, and it 
poisons const to the point where you really should consider any const 
variable to be also shared.

-Steve


More information about the Digitalmars-d mailing list