--- Comment #2 from 2010-04-04 07:56:58 PDT ---
This is a (possibly silly) idea for a low-priority enhancement, to allow the
allocation of class instances at compile-time. This can be useful because their
creation time can be moved from run-time to compile-time.

When a class is instantiated at compile-time, it can be used and it can even
get garbage collected. When the compile-time computation ends, the compile-time
GC must collect all unused class instances (otherwise you can't tell what class
instance the compiled program will contain. The compile-time GC can be a
reference counter too, that is more deterministic) and put the active ones in a
data segment of the binary.

If a class instance is mutable, but the data segment is read-only, then at the
start of run time the runtime has to copy it into the heap and to update the
internal pointers and references.

To reduce implementation complexity, the compile-time class instances can be
immutable only, so there's no need to copy them to the heap and change the
pointers. If the the class instance is immutable but its reference is mutable
then the class instance may need a mutable boolean somewhere to tell if it's
it's garbage-collected at runtime (because it can't be really deleted from the

This whole idea is related to the section "Pointer Hydration" written by
Walter, the main difference is that it's done by the compiler (and the data is
stored inside the binary itself), so for the programmer it's safer and simpler
to use:

Such loading of already initialized class instances is commonly done in games
written in C++, see for example the "Fast data load trick" in the Game
Programming Gems 1 book.

Many things in D are designed taking the idea from a common C++ idiom, where it
is usually implemented in a more or less manual way, and change it into a
explicit D construct, that is semantically clean and possibly safer. So this
compile-time class instances can be another exaple of such kind of idiom

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to