Immutable Message Passing

Andrew Wiley wiley.andrew.j at
Sun Dec 4 14:32:17 PST 2011

On Sun, Dec 4, 2011 at 4:23 PM, Andrei Alexandrescu
<SeeWebsiteForEmail at> 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?

More information about the Digitalmars-d mailing list