ponce

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


On Tue, 09 Nov 2010 17:14:33 -0500, Don <nospam at nospam.com> wrote:

> bearophile wrote:
>> Jonathan M Davis:
>>
>>> it would be possible to make it so that any objects allocated with new  
>>> during CTFE would be in the dynamic heap during runtime.
>>  This is possible, but it doesn't seem what you usually desire when you  
>> allocate an object at compile time.
>>  Bye,
>> bearophile
>
> If it's mutable, it'll go on the heap. If it's immutable, it could  
> optionally go into read-only memory (it will be exactly like the .init  
> of a class instance). Classes which are used only during execution of  
> CTFE functions will not be instantiated at runtime.

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?

-Steve


More information about the Digitalmars-d-learn mailing list