Variable-length stack allocated arrays
Leandro Lucarella
llucax at gmail.com
Tue Jan 12 06:07:44 PST 2010
bearophile, el 12 de enero a las 04:18 me escribiste:
> Walter Bright:
> > One of the problems is they can easily lead to stack exhaustion. Stack
> > sizes for a thread must all be preallocated.
>
> Yes, that's of course a problem. It's meaningful to allocate arrays on the stack only if they are small. You can exhaust the/a stack even with normal fixed-sized arrays too:
>
> int foo(int n) {
> int[100] a;
> ...
> y = foo(k);
> ...
> }
Or with structs:
struct S {
int[100000] a;
}
void foo() {
S s;
}
See this post:
http://www.yosefk.com/blog/the-c-sucks-series-petrifying-functions.html
For a nice real story about this problem ;)
--
Leandro Lucarella (AKA luca) http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
This homeless guy asked me for some money the other day.
And I was gonna give it to him but then I thought you're
just gonna use it on drugs or alcohol.
And then I thought, that's what I'm gonna use it on.
Why am I judging this poor bastard.
More information about the Digitalmars-d
mailing list