Steven Schveighoffer schveiguy at yahoo.com
Wed Nov 10 10:36:55 PST 2010

On Wed, 10 Nov 2010 13:08:10 -0500, Jonathan M Davis <jmdavisProg at gmx.com>  

> On Wednesday, November 10, 2010 07:55:42 Steven Schveighoffer wrote:

>> Pardon my ignorance, but how can something evaluated at compile time go  
>> on
>> the heap?  The heap doesn't exist yet!
>> e.g.:
>> class C
>> {
>>    int[] buffer;
>>    this() pure { buffer = new int[125];}
>> }
>> C c = new C;
>> How does c go on the heap at compile time?  Won't you have to re-run the
>> constructor at runtime to get the right result?  Not only that, but even
>> if you did run the ctor at compile time, how do you make a copy of c for
>> every thread without re-running the ctor?
> You likely end up essentially serializing it. You then deserialized it  
> and bring
> it into the heap when the program loads. It's not a particularly pretty  
> problem,
> but it should be quite doable. You certainly wouldn't rerun the  
> constructor or
> whatnot. What you need is to just transfer its saved state onto the heap,
> translating any pointers and references that it has to whatever they  
> should be
> in the current heap.

Wow, this seems like a lot of extra effort for zero gain.  Is this really  
the direction we are going?  Why can't we just say anything decided at  
compile time must be immutable or implicitly converted to immutable, and  
anything else you have to do in a static constructor?


More information about the Digitalmars-d-learn mailing list