Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a program which have 4 projects as dependency for that (that means it has to load 4 dlls to run that program) .Does the OS allocates 4 stack memories or only 1 stack memory will be allocated for whole program and how much stack memory size will be allocated for the program?
Posted
Comments
Afzaal Ahmad Zeeshan 28-Feb-15 6:53am    
Depends on your program, the objects, their type; class or struct or default objects such as int char etc.

How can you even believe that we would be able to share our knowledge about some thing that we don't even know exist. Programmers don't believe in Myth. Share the code, get the answer.
Sergey Alexandrovich Kryukov 28-Feb-15 9:11am    
Let me guess: stack overflow? If so, it's unlikely the stack size problem. :-)
—SA

1 solution

Depends: a stack is associated with each thread that the application runs: so if it only ever starts one thread - it's main thread - and doesn't do anything to start any more, then it will get one and only one stack.

That's not strictly accurate (as there is a separate stack that is used by device drivers that your app may interface with and such like) but it's accurate enough for 99.99% of applications!

The actual size of the stack is variable at build time, (See MSDN: /F flag[^]) and also may vary depending on the environment your app runs in. It does not change at run time.

[edit]Typo[/edit]
 
Share this answer
 
v2
Comments
krish0969 28-Feb-15 7:54am    
Thanks for the valuable feedback :).As I said I have 4 projects and in those projects I am not creating threads.So in each project suppose if I give different stack size using compile option then whats the actual stack memory will be allocated for the app
OriginalGriff 28-Feb-15 7:58am    
No, it doesn't work like that: a DLL doesn't have a stack size, unless it starts a thread.
When you run an EXE file, it starts with a single thread, and a single stack as a result. Unless you start a thread, or another process, you will stay on the same thread until your app exits
krish0969 28-Feb-15 8:18am    
Thanks for clearing the doubt:)
OriginalGriff 28-Feb-15 8:41am    
You're welcome!
krish0969 28-Feb-15 9:11am    
I have one more question.How much memory max can be allocate for global variables.I know that global and static variables are stored in data segments but is this segment have fixed memory like stack.Can we declare array with large amount of memory ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900