Stack Size

Aug 26, 2012 at 7:37am
Hello, I would like to ask how much in average is the stack size ?

I would like to create a simple game using SFML, and I wonder if I should allocate memory on the heap for images.
Aug 26, 2012 at 8:15am
closed account (zb0S216C)
Wisely Done wrote:
"I would like to ask how much in average is the stack size ?"

Last time I checked, it's 1MB. I've seen an option somewhere in Visual Studio where you can change the default stack size.

Wisely Done wrote:
"I wonder if I should allocate memory on the heap for images."

Normally, images are quite large, even smaller ones; far too big to be placed on the stack. Your best bet is to allocated such resources on the heap.

Wazzak
Last edited on Aug 26, 2012 at 8:16am
Aug 26, 2012 at 8:35am
Should I reserve like 10 MB for stack size and avoid dynamic memory allocation ?
Aug 26, 2012 at 8:43am
closed account (zb0S216C)
It's possible to reserve a stack of that size, but only in Visual Studio. Besides, you're better off using the heap.
I suggest either implementing a linked-list, or allocating a pool of memory, and placing a resource inside the pool.

Wazzak
Aug 26, 2012 at 9:18am
If you create a sf::Image on the stack only sizeof(sf::Image) bytes will be stored on the stack. The actual pixel data will be stored on the heap so it's probably not much to worry about.
Topic archived. No new replies allowed.