Originally Posted By: Khaled
"Every page that is reserved for the stack cannot be used for any other purpose."

On my Windows 7, there are currently 74 processes, and many threads (each of which require their own stack space), running in the background. If they all set a reserved stack space of 32MB, that would require at least 2.4G of reserved stack space.

I'm afraid you're misinterpreting the text from Microsoft. The full text shows that "reserved" means "set aside for that purpose in the process's virtual address space" in this context. It does not mean that all of that virtual address space has physical pages backing it. The virtual stack pages will only have associated physical memory if they 1) are part of the initially committed set, or 2) have been actually used at some point. Thus, increasing the maximum ("reserved") stack size does not automatically lead to more memory usage. On the other hand, once a stack page has actually been used at any point, it basically cannot be freed anymore, so that in mIRC's single-threaded case..

Originally Posted By: Wims
however that memory used is released at the end so it's not really an issue I think

.."the end" is the moment that mIRC exits, and no earlier.

Originally Posted By: Khaled
I did some more testing and noticed that with a stack size of 32MB the first time I called the recursive alias, it took about four seconds to complete. The second time, and every time afterwards, it took ten seconds to complete.

One possible explanation is that Windows aggressively swaps large stacks to the page file, which means that for all but the first time, the pages need to be reread from disk before they can be reused. Task Manager can probably confirm (or deny) this.

Originally Posted By: Khaled
Apart from the above, increasing stack space, which will affect all mIRC users, possibly negatively, just to increase the recursion limit to an arbitrary and still limited value that will only be useful in a small number of cases, and is both more speed and memory intensive than an iterative solution, does not seem reasonable.

I completely agree. The examples given so far can easily be implemented iteratively, and with hardly any extra code to boot.

Last edited by Sat; 24/01/15 04:59 PM. Reason: proper quote attribution

Saturn, QuakeNet staff