<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Perhaps if you declared some function as lazy, then the compiler would<br>
be expected to cache the return value<br>
</blockquote>
<br></div>
How does it cache it?<br>
<br>
i.e.<br>
<br>
- What data structure does it use?<br>
- Is there a size limit, or does it just keep adding into the cache until you run out of memory?<br>
- What allocator does it use?<br>
- If there is a size limit, what is the eviction policy?<br>
- and what is the size limit?<br>
- How do I manually flag the cache as dirty if I want to clear it?<br>
<br>
There is no automatic way to do caching. Every single application of caching has its own needs and you need control over that. You can't just stick it all in a hash table and be done with it.<br>
</blockquote></div><br><div>I can imagine many possibilities. Here's one straight off the top.</div><div><br></div><div>- The data structure is the return value of the function contained within its parent class/struct + any necessary dirty bits. Where you place those it in the containing class/struct is debatable, but sensible options exist.</div>
<div>- Size limit? What is the size limit of the object returned from the function in the first place?</div><div>- Not really relevant, if it's a primitive type or struct, it is contained by the functions containing object, if it is a class, then it is a reference to, and it is allocated however the lazy function does.</div>
<div>- I don't think this is relevant.</div><div>- Again...</div><div>- Fair question. Perhaps the function could have a property, or the containing class could have some property to access the cached object... but I would imagine the compiler would explicitly manage dirtying of the state, so that it can enforce that it is done in a '@safe' way...</div>
<div><br></div><div>Am I wrong in suggesting that this is the most frequent cause of people raising the "D const issues' topic?</div>