Possible way to achieve lazy loading with const objects

Jonathan M Davis jmdavisProg at gmx.com
Wed Sep 28 13:03:51 PDT 2011


On Wednesday, September 28, 2011 11:31:31 Christophe wrote:
> "Jonathan M Davis" , dans le message (digitalmars.D:145479), a écrit :
> > But since lazy initializion will _never_ work with immutable
> 
> Never say never. One could build a clean and thread-safe way to lazily
> initialize fields. Like someone said, even without mutex, if the
> function to compute the variable is pure and based on immutable data,
> the worst case would be to run the intializing function twice. And the
> langage could include mutexes to do prevent that to happen. The fact
> that immutable data could, one day, be put in ROM doesn't mean that it
> has to. The close issue is like another-one said the issue of
> memoization of pure methods.

The very fact that an immutable variable _could_ be put into ROM negates the 
possibility of the semantics being such that you don't have to fully 
initialize an immutable variable up front.

- Jonathan M Davis


More information about the Digitalmars-d mailing list