1
General / Using the stack or the heap for SFML objects
« on: April 12, 2013, 12:25:44 am »
All the example code I've seen for SFML creates objects such as textures and sprites as follows:
I don't see the new keyword anywhere here, so I'm assuming this means the objects are created on the stack, and not on the heap? Surely this is a bad idea, since with a decent size codebase you'll eventually exceed the stack size and get stack overflow issues?
So my question is this: should I create new objects on the heap or on the stack? Or is SFML internally managing memory allocation in such a way that the stack isn't actually used?
Code: [Select]
sf::Texture texture;
texture.loadFromFile("texture.png"))
sf::Sprite sprite;
sprite.setTexture(texture);
I don't see the new keyword anywhere here, so I'm assuming this means the objects are created on the stack, and not on the heap? Surely this is a bad idea, since with a decent size codebase you'll eventually exceed the stack size and get stack overflow issues?
So my question is this: should I create new objects on the heap or on the stack? Or is SFML internally managing memory allocation in such a way that the stack isn't actually used?