RCArray is unsafe

Zach the Mystic via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 3 19:46:34 PST 2015


On Tuesday, 3 March 2015 at 21:37:20 UTC, Andrei Alexandrescu 
wrote:
> On 3/3/15 12:35 PM, Zach the Mystic wrote:
>> Isn't allocating and collecting a freelist also overhead?
>
> No. I don't have time now for a proof of concept and it seems 
> everybody wants to hypothesize about code that doesn't exist 
> instead of writing code and then discussing it.

Okay.

>> The unoptimized lowerings would be:
>>
>> {
>>   auto tmp = myGlobal; // bump count
>>   impureFun(myGlobal);
>> }  // tmp destroyed, --count
>>
>> {
>>   auto tmp2 = c; // bump count
>>   fun(c, c);
>> } // --count
>>
>> The only addition is an optimization where the compiler elides 
>> the
>> assignments and calls the add/release cycles directly.
>
> Do you have something reviewable, or just your own past posts?

Just my own past posts. My suggestion is based on the compiler 
doing all the work. I don't know how it could be tested without 
hacking the compiler.

> For the time being I want to move forward with DIP25 and 
> deferred freeing.

That's fine. I like DIP25. It's a start towards stronger safety 
guarantees. While I'm pretty sure the runtime costs of my 
proposal are lower than yours, they do require compiler hacking, 
which means they can wait.


More information about the Digitalmars-d mailing list