c - Stack and Heap Space for Modern Computers -


While writing in C, how can I tell how much stack space is available in memory when I launch a program is? How about map space?

How can I tell how much memory is being used during my program execution?

This is all Win32-specific (not really C-specific, all just OS API):

When a thread is created, it gets 1MB of stack space by default, whatever you use the CreateThread API can be modified.

You can peek at the Thread Notification Block to find the actual stack information, but even though this is a document, this technique is not officially supported. Also, for 32-bit applications, you can only address up to 2 GB, so for an app that much memory is used by the design, then the thing to look at is the total size of the process' virtual address Location (committed + reserved), which includes all stack allocation, you can access the virtual memory of the progressive process with the Global MemoryStatsX API, Virtual Address Space See the ultimate once close to your process 1.8 or 1.9 GB VAS, then stack allocation and starts to fail virtual Alalk calls. For "normal" apps, you do not have to worry about running out of VAS, but it's always good to check out fail allocations. In addition, you should not get stack overflow, unless you have a bug or poor design.


Comments