3 ms·
Is it? Last time I checked a few years ago there were huge caveats to allocation Objects on the stack (I forget what they were) so unless something's drasticall
by mehrdadn 9y ago
Is it? Last time I checked a few years ago there were huge caveats to allocation Objects on the stack (I forget what they were) so unless something's drastically changed this doesn't seem like an honest assessment.
- destructionator 9y agoThe pitfalls aren't really any different than C++... either use some kind of smart pointer, or use caution not to escape references to stack memory (very easy mistake to make in D) or slice up the object by value (very difficult to do in D) and you'll be fine. The built-in `scope` syntax is deprecated (though making a comeback recently as more stuff gets implemented around it), but you can also do a library type fairly easily, just slightly heavier in syntax (you need to prepare the memory and construct the object in two separate lines) or prep work (write a struct which does both).
- mhh__ 9y agoIf you want to allocate an object on the stack, then use std.conv : emplace and alloca. This(https://wiki.dlang.org/Memory_Management#Allocating_Class_Instances_On_The_Stack https://wiki.dlang.org/Memory_Management#Allocating_Class_In...) method also exists but is on the road to deprecation