large arrays on the stack cause segfaults

Sage
Posts: 1,482
Joined: 2002.09
Post: #1
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?

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
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.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #3
Which would explain why it choked on a 2048 x 2048 RGBA texture. That's 16MB right there. Whoops. Blush

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  usage of packages in large Java project JeroMiya 2 2,316 Jul 20, 2007 04:02 PM
Last Post: AndyKorth