🔒 Locked
Stack vs heap...
Advertisement
Original Post
How much stuff is too much to put on the stack before you start getting overflow errors and the such? eg should ALL variables in class''s be taken off the heap etc?
CEO Plunder Studios
I'm not sure about the stack size, but I always imagined that the OS sets aside a certain chunk of memory as stack memory (how much is up to avaible RAM and what OS you're using, I think), and if your program uses up all of that memory, you get a stack overflow. I don't know what you mean by "should all variables in classes be taken off the heap" because when you create an object of automatic storage class then all fields of that object will be on the stack too. If you create an object using dynamically allocated memory (created on heap via new operator), all data members of that object will be on the free store too. Of course, there's the third possibility that you create an object of static storage class and in that case all fields of that object will be put in the static section of memory designated by the OS. I hope I'm not wrong (just learning C++) and I hope I wasn't too confusing either. Take care
.
[edited by - fallenang3l on April 12, 2002 11:28:26 PM]
[edited by - fallenang3l on April 12, 2002 11:28:26 PM]
I believe the default Stack size is 1024 bytes. You can change the size of the stack (see your compiler''s documentation).
Well one megs more than enough isnt it...
And I mean something like so:
CEO Plunder Studios
And I mean something like so:
class AClass
{
public:
AClass()
{
Var1 = new int;
Var2 = new int;
}
// methods here
private:
int *Var1;
int *Var2;
};
AClass *instance1 = new AClass;
CEO Plunder Studios
If you did this:
Then nothing would be created on the stack. The
codeka.com - Just click it.
class AClass
{
public:
AClass() {}
private:
int var1;
int var2;
};
AClass *inst = new AClass;
Then nothing would be created on the stack. The
inst pointer would be in your data block, and the two variables AClass::var1 and AClass::var2 would be on the heap. codeka.com - Just click it.
I tried searching google and VC++ 7''s docs, but I couldn''t find how to figure out the default stack size a program starts with. Is there a function call or something?
Ywah I know thats what I meant, its just the first guy seemed a little confused...
CEO Plunder Studios
CEO Plunder Studios
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement