Generic and fundamental language design issue
Tommi
tommitissari at hotmail.com
Sun Nov 4 11:42:28 PST 2012
On Sunday, 4 November 2012 at 18:14:36 UTC, Dmitry Olshansky
wrote:
> In fact placing big object on stack just because it fits could
> introduce stack overflow few hundred calls later.
But that's kind of my point also. For example:
void func(T)(int n)
{
if (n <= 0)
return;
auto t = <create variable t of type T>
...
func!(T)(n - 1);
}
If func is called with a runtime argument n, then the programmer
cannot determine the most sensible way to allocate for variable
t. What I'd like to happen is that, at runtime, every time a
variable t is created, the program would determine the best way
to allocate the memory for it, based on the available stack size
(prefer stack if there's room there).
On Sunday, 4 November 2012 at 18:14:36 UTC, Dmitry Olshansky
wrote:
> In general compiler can't know beforehand how big stack space
> you'll need and thusly the portion of it to use safely.
Yeah, I just realized it can't be done at compile-time. Making
the decision between stack or heap allocation should happen at
run-time.
More information about the Digitalmars-d
mailing list