Click here to Skip to main content
15,913,282 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: need help Pin
progDes2-Sep-07 0:36
progDes2-Sep-07 0:36 
GeneralRe: need help Pin
Russell'2-Sep-07 0:43
Russell'2-Sep-07 0:43 
QuestionRe: need help Pin
Russell'2-Sep-07 0:54
Russell'2-Sep-07 0:54 
AnswerRe: need help Pin
progDes2-Sep-07 1:09
progDes2-Sep-07 1:09 
GeneralRe: need help Pin
Mark Salsbery2-Sep-07 8:58
Mark Salsbery2-Sep-07 8:58 
AnswerRe: need help Pin
progDes2-Sep-07 1:23
progDes2-Sep-07 1:23 
GeneralRe: need help Pin
Russell'2-Sep-07 2:09
Russell'2-Sep-07 2:09 
GeneralRe: need help Pin
Mark Salsbery2-Sep-07 8:52
Mark Salsbery2-Sep-07 8:52 
I should have been more clear with the term "stack variable"...

I should have separated static and automatic variables:
// Outside of a function/method/object is implicitly static

// This is NOT on the stack
int a[10000];

void SomeFunc()
{
...
}

// Inside a function/method and marked static

void SomeFunc()

{
   // This is NOT on the stack
   static int a[10000];
...
}

// Inside a function/method and NOT marked static

void SomeFunc()
{
   // This is an "automatic" variable
   // This IS on the stack!
   int a[10000];
...
}

Objects created with "new" are generally on the runtime heap (unless you're
using a custom new operator and allocating memory some other way).

The stack is created at runtime when creating threads.  The default size of the stack
for the primary thread of an executable is set by the linker, so I can't imagine
the compiler can tell you you've created too big of a stack variable.  At runtime, however,
there will be a fault if you use too much stack space (stack overflow).

The stack is good for small, temporary objects.  Allocating room on the stack is much faster
than allocating memory on the heap. Large objects should be created on the heap
regardless of their longevity.  How big "small" and "large" objects are varies, depending
on stack size, nested function call depth, how many other objects are on the stack, etc.
Usually it's recommended that objects larger than a few KB should be dynamically allocated
on the heap, but again, that's arbitrary, and depends on the design of the application and the
system it's running on.

Hopefully a little more info,
Mark



Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: need help Pin
Russell'2-Sep-07 21:39
Russell'2-Sep-07 21:39 
QuestionHow to Copy from iPhone using Windows API Pin
Brian C Hart1-Sep-07 13:17
professionalBrian C Hart1-Sep-07 13:17 
QuestionCTabStrip VC++ Google returns ONE article !! Pin
Vaclav_1-Sep-07 8:10
Vaclav_1-Sep-07 8:10 
AnswerRe: CTabStrip VC++ Google returns ONE article !! Pin
Mark Salsbery1-Sep-07 8:13
Mark Salsbery1-Sep-07 8:13 
GeneralRe: CTabStrip VC++ Google returns ONE article !! Pin
Vaclav_1-Sep-07 9:24
Vaclav_1-Sep-07 9:24 
QuestionCreate functionally release version Pin
barbarini1-Sep-07 7:34
barbarini1-Sep-07 7:34 
AnswerRe: Create functionally release version Pin
Mark Salsbery1-Sep-07 8:08
Mark Salsbery1-Sep-07 8:08 
GeneralRe: Create functionally release version Pin
bob169721-Sep-07 8:30
bob169721-Sep-07 8:30 
GeneralRe: Create functionally release version Pin
Mark Salsbery1-Sep-07 9:11
Mark Salsbery1-Sep-07 9:11 
Questionhow to create sin() and log() functions of myown? Pin
includeh101-Sep-07 6:12
includeh101-Sep-07 6:12 
AnswerRe: how to create sin() and log() functions of myown? Pin
El Corazon1-Sep-07 8:18
El Corazon1-Sep-07 8:18 
AnswerRe: how to create sin() and log() functions of myown? Pin
Stephen Hewitt3-Sep-07 15:11
Stephen Hewitt3-Sep-07 15:11 
QuestionCAsyncSocket problem Pin
__yash__1-Sep-07 6:02
professional__yash__1-Sep-07 6:02 
AnswerRe: CAsyncSocket problem Pin
Mark Salsbery1-Sep-07 7:15
Mark Salsbery1-Sep-07 7:15 
GeneralRe: CAsyncSocket problem Pin
__yash__1-Sep-07 23:27
professional__yash__1-Sep-07 23:27 
GeneralRe: CAsyncSocket problem Pin
Mark Salsbery2-Sep-07 9:12
Mark Salsbery2-Sep-07 9:12 
QuestionCatching exceptions MFC Pin
barbarini1-Sep-07 5:34
barbarini1-Sep-07 5:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.