From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d02eb5c33ac65d9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-03-11 09:41:46 PST Message-ID: <3E6E1EFA.6030802@cogeco.ca> From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Array and memory usage References: <1ec946d1.0303100713.7f7bcbb7@posting.google.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 11 Mar 2003 12:38:02 -0500 NNTP-Posting-Host: 198.96.47.195 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1047404284 198.96.47.195 (Tue, 11 Mar 2003 12:38:04 EST) NNTP-Posting-Date: Tue, 11 Mar 2003 12:38:04 EST Organization: Bell Sympatico Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!torn!webster!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail Xref: archiver1.google.com comp.lang.ada:35213 Date: 2003-03-11T12:38:02-05:00 List-Id: Robert A Duff wrote: > mheaney@on2.com (Matthew Heaney) writes: >>Robert A Duff wrote in message news:... >> >>>If you use this trick on Windows, it will allocate backing store for all >>>that virtual memory. I believe most Unix systems are smarter than that. >>> >>>This trick is sometimes more efficient than linked lists for growable >>>data structures. The links waste space, plus if you're not careful, the >>>list gets scattered all over the place, damaging cache behavior. The >>>nice thing about arrays is that they are contiguous. >> >>One thing you can on Windows is simply reserve the virtual memory for >>the array, without committing it to physical memory, and then use SEH >>("structured exception handling") to handle the error. >> >>The SEH mechanism supports resumption semantics, so you can handle the >>exception by committing the page you need, and then resuming from the >>spot from where the exception was raised. >> >>This is documented in Jeff Richter's Programming Applications book. > > I thought it happened automatically. That is, if I say: > > X: array (1..100_000_000) of Integer; > > it would allocate 400,000,000 bytes of virtual memory, but only allocate > physical pages on demand. I believe that much works on Windows (without > calling windows-specific stuff like SEH). (Windows 2000, Windows XP.) > The problem I found was that it allocated 400,000,000 bytes of backing > store, which was annoying. > > Am I misinformed? > > - Bob Where it is defined also makes a difference. If you do: procedure Foo is X: array (1..100_000_000) of Integer; begin ... then this will use the _stack_ (considerably at that). If your stack is too small (or too small because it has been split up between many tasks), this has no hope of succeeding without blowing up, or corrupting memory beyond the stack (or end of) if the stack overflow goes undetected. The pages are committed on the stack as they are used AFAIK, for most platforms. -- Warren W. Gay VE3WWG http://home.cogeco.ca/~ve3wwg