On Sunday, 4 November 2012 at 18:14:36 UTC, Dmitry Olshansky
wrote:
extern(C):
int blah(void* ptr);
void func(T)()
{
auto t = <allocate T from heap or stack?>
blah(&t); //now what?
...
}
If blah doesn't store pointer somewhere inside you are fine
with stack. If it does then not even GC heap will help you.
In a perfect world, I think, the compiler would see that blah
stores ptr and therefore would (implicitly) allocate t on the
heap. The deallocation of the memory for t would be handled
either by garbage collector or by some kind of implicit reference
counting.
I guess with extern C functions none of the above is doable.