[computer-go] Allocating lots of memory in C++?

Dave Denholm ddenholm at esmertec.com
Thu Aug 17 01:42:14 PDT 2006


"Mike Young" <mikewhy at sbcglobal.net> writes:

> You probably have your answer by now about why your huge stack var
> failed. Here's some more detail about how Windows treats the
> stack. Other OS'es will likely be similar. 
>
> The initial stack allocation is specified in the link step. You can
> change this value via flags. The default in Win32 is 1 MB. The
> smallest valid allocation is 64KB, the virtual page granularity. It
> starts on a 64kb boundary, for what that's worth. The OS maintains a
> small guard page beyond the end of this allocation. I don't recall
> its size. Accessing this guard page triggers a segmentation fault,
> causing the fault handler to extend the stack. Stack vars are
> typically much smaller than your huge array. It exceeded the limit
> of that guard page, and so did not trigger stack
> expansion.

I have a vague recollection that if there was more than 2 pages of
automatic variables, the compiler inserted code to deliberately touch
each page, just to ensure that this didn't happen. But that probably
depends on compiler version, etc.


dd
-- 
Dave Denholm              <ddenholm at esmertec.com>       http://www.esmertec.com


More information about the computer-go mailing list