Immutable Message Passing

Timon Gehr timon.gehr at gmx.ch
Sun Dec 4 16:19:35 PST 2011


On 12/04/2011 11:32 PM, Andrew Wiley wrote:
> On Sun, Dec 4, 2011 at 4:23 PM, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org>  wrote:
>> On 12/4/11 4:16 PM, Andrew Wiley wrote:
>>>
>>> So it looks like right now, message passing is copying objects, which
>>> seems very bad. Check this out:
>>> --------
>>> import std.stdio;
>>> import std.concurrency;
>>>
>>> class Bob {
>>> }
>>>
>>> void main() {
>>>
>>>         auto tid = spawn(&func);
>>>         auto bob = new shared(Bob)();
>>>         writeln("bob is currently at ", cast(void*)(&bob));
>>
>>
>> This is the address of the reference, not that of the object. Use
>> cast(void*)(bob).
>>
>> Andrei
>
> Ah, I am covered with shame.
>
> In that case, no object copying is occurring, and I have message
> passing for immutable objects working, although my current solution is
> basically to check whether the object is immutable, and if so, memcpy
> the reference. That breaks immutability, but only for the reference,
> and I don't think there's any alternative unless we get tail
> const/immutable into the language.
>
> I'm guessing this is too hackish to get merged into std.variant?

You might want to have a look at std.typecons.Rebindable.


More information about the Digitalmars-d mailing list