digitalmars.D - D gc on local objects
- monnoroch (17/17) Apr 16 2014 I often see, that D developers say something like "remove
- Adam D. Ruppe (6/6) Apr 16 2014 This is one of the things the `scope` storage class on local
- John Colvin (4/10) Apr 16 2014 I would love to have a "scope" that works properly, with or
- Adam D. Ruppe (5/8) Apr 16 2014 The blade guards are the important part though: if you just want
- Paulo Pinto (8/14) Apr 16 2014 Not allowing a variable to escape scope should be easily done with
I often see, that D developers say something like "remove allocations from std lib", and it seems, that the main reason to do it is eliminate gc calls. What about the idea, that local objects do not use gc at all? Maby, all temporary variables can be destroyed just like in C++, when out of scope without stop-the-world? Here's a silly example: bool hasDot(string s1, string s2) { auto tmp = s1 + s2; return tmp.find(".") != -1; } Clearly, the tmp variable allocates, but there is no point to do it via gc, since all memory is allocated and used in specific scope. What if dmd could fins those variables and swich gc allocation to just malloc+constructor call, and destructor+free call at the end of a scope?
Apr 16 2014
This is one of the things the `scope` storage class on local variables can do, but since it isn't implemented properly, it is not memory safe and thus its usage is deprecated. I really really really want to see scope be fully implemented, including not allowing a reference to the variable to escape the scope, but this is easier said than done.
Apr 16 2014
On Wednesday, 16 April 2014 at 16:51:57 UTC, Adam D. Ruppe wrote:This is one of the things the `scope` storage class on local variables can do, but since it isn't implemented properly, it is not memory safe and thus its usage is deprecated. I really really really want to see scope be fully implemented, including not allowing a reference to the variable to escape the scope, but this is easier said than done.I would love to have a "scope" that works properly, with or without blade-guards to stop me chopping off my hands when the function returns.
Apr 16 2014
On Wednesday, 16 April 2014 at 17:14:55 UTC, John Colvin wrote:I would love to have a "scope" that works properly, with or without blade-guards to stop me chopping off my hands when the function returns.The blade guards are the important part though: if you just want the allocation pattern, you can do that fairly easily yourself with plain library code and stuff like scope(exit) or raii destructors.
Apr 16 2014
Am 16.04.2014 18:51, schrieb Adam D. Ruppe:This is one of the things the `scope` storage class on local variables can do, but since it isn't implemented properly, it is not memory safe and thus its usage is deprecated. I really really really want to see scope be fully implemented, including not allowing a reference to the variable to escape the scope, but this is easier said than done.Not allowing a variable to escape scope should be easily done with dataflow analysis if I recall correctly. Now, I don't have any idea how easy/simple it is to implement it in the existing code base, in a compatible way across all three compilers. So just speaking out of my soap box. -- Paulo
Apr 16 2014