RCArray is unsafe

Zach the Mystic via Digitalmars-d digitalmars-d at puremagic.com
Tue Mar 3 07:30:42 PST 2015


On Tuesday, 3 March 2015 at 05:12:15 UTC, Walter Bright wrote:
> On 3/2/2015 6:04 PM, weaselcat wrote:
>> On Tuesday, 3 March 2015 at 01:56:09 UTC, Walter Bright wrote:
>>> On 3/2/2015 4:40 PM, deadalnix wrote:
>>>> After moving resources, the previous owner can no longer be 
>>>> used.
>>>
>>> How does that work with the example presented by Marc?
>>
>> He couldn't pass s and a member of s because s is borrowed as 
>> mutable.
>> He would have to pass both as immutable.
>
> A pointer to s could be obtained otherwise and passed.

Under normal circumstances, if the pointer to s is an lvalue, the 
refcount will be bumped when it is taken.

Isn't the only problem now aliasing something (i.e. a global) 
invisibly through a parameter? This is easily solved -- when 
passing a global reference, or duplicating a variable in the same 
call, wrap the call in an add/release cycle. This preserves the 
alias for the duration of the call.

Or are we also talking about taking the address of a non-rc'd 
subcomponent of an rc'd struct?


More information about the Digitalmars-d mailing list