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?
1 Answers
It all depends ! Your projects can be independent applications or libraries:
- Independent application each have their own stack
- Libraries will be linked to application and don't have their own stack
DLLs are libaries that are dynamically linked, so they follow the principle of libraries and don't have their own stack.
Applications however can have multiple threads (and for example run functions exposed in the libraries in different threads). Each thread has its own stack.
With Windows, the default stack size is specified in the executable file header. The default stack reservation size used by the linker is 1 MB. Look at this SO question for stack defaults on other OS.
Note that the number of threads in a programme is dynamic: your programme may at any time use standard C++ library or OS calls to create or terminate them. But if your code uses this, you'll notice. The same applies for processes, if your application launches some.

- 1
- 1

- 68,716
- 7
- 72
- 138
-
Thanks for the valuable response.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 a global variable array with large amount of memory ? – krish Feb 28 '15 at 14:12
-
It depends if for win32 (2GB, 4GB if compiled with /LARGEADDRESSAWARE and running on 64 bits windows) or for x64 (8TB) see here: https://msdn.microsoft.com/en-us/magazine/cc300794.aspx . This memory is total address space = (static+global) + stack + heap + programme code. THis article may interest you also for the general understanding: http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory/ – Christophe Feb 28 '15 at 14:38