PDA

View Full Version : large arrays on the stack cause segfaults


Skorche
2007.05.23, 11:40 PM
I've been toying around with procedural texture generation for the last couple days. I noticed that creating very large (several megabytes) arrays on the stack causes segfaults. Using heap space is a simple enough solution, but how do you know how much stack space is available to avoid the problem in the first place?

OneSadCookie
2007.05.24, 12:34 AM
Depends on how much the compiler allocated you (for the main thread) and on how much you asked for (for secondary threads).

According to an Apple web page, pthreads get a 512KB stack by default, so you should probably try to stick well under that.

IIRC, GCC gives the main thread about 8MB by default.

Skorche
2007.05.24, 02:50 AM
Which would explain why it choked on a 2048 x 2048 RGBA texture. That's 16MB right there. Whoops. :blush: