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-Thread: 103376,be7fa91648ac3f12 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!newscon06.news.prodigy.com!prodigy.net!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Wed, 13 Apr 2005 14:52:29 -0500 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: Subject: Re: Large arrays (again), problem case for GNAT Date: Wed, 13 Apr 2005 14:54:48 -0500 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4927.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200 Message-ID: NNTP-Posting-Host: 64.32.209.38 X-Trace: sv3-LIJ/82ddQwShfHnaxNyABedJHskLJGiqQPjqCwbEIUfGzNwrCCMCBVWRc3Ggefw0kK0SHx0kZ2yEtj1!Sj8P2tEy9fMyj+ws8xsyrIIXIq4WPUx69CFUjFMD53vrxWe5/fcTtx9KhvUP28fe4SEJMqpYwK3m X-Complaints-To: abuse@megapath.net X-DMCA-Complaints-To: abuse@megapath.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:10439 Date: 2005-04-13T14:54:48-05:00 List-Id: "Dr. Adrian Wrigley" wrote in message news:pan.2005.04.13.12.46.52.518681@linuxchip.demon.co.uk.uk.uk... > Hi guys! > > A month or two back I hinted that I had been having problems > the GNAT code accessing large data structures. It seemed that > incorrect code was silently being generated. Since I didn't > have a test case available, no progress could be made. I tried to make an all-Ada version to test on Janus/Ada. But there is not enough memory on my machine to run it (at least, I think that's why I'm getting Storage_Error; the Janus/Ada runtime bypasses the system heap and goes directly to the Windows virtual memory manager for large blocks of memory, so the failure should indicate that Windows couldn't allocate it.) I made three changes to the program: Added a type Big_Int to replace Integer (better portability, especially for a compiler with Integer'Size = 16); Replaced the GNAT-specific "Address_Image" with System.Storage_Elements.Integer_Address (clunky, but pure Ada); Replaced the call to Malloc with New. The latter was done simply because end-running the compiler's memory management is likely to cause bugs. And ours, at least, is designed to work with any reasonable-sized chunk of memory. Finally, if I hadn't changed that, it would not have worked, as Janus/Ada does not allow random memory to be used with a pool-specific type. (Really, the access type should be a general access type if you are going to end-run Ada's heap management.) The test works with small enough numbers to run on my machine with 384Meg of RAM (the top value being about 130_000_000). If you were our customer, I'd try to figure out why the Storage_Error is being raised. Probably the answer really is to use a supported compiler; you do really get what you pay for. Randy. with Text_IO; with System.Storage_Elements; -- Added, RLB. procedure TestBig2 is -- Test devised by Adrian Wrigley, amtw@linuxchip.demon.co.uk.uk.uk (one uk is e -- I disclaim all rights to this code. Do what you wish with it! -- This test case illustrates a problem with code -- compiled on GNAT 3.15p for x86 under Linux -- It shows that the 'Address of elements of large -- arrays can be silently incorrect -- Redid by Randy Brukardt to work with Janus/Ada; added an appropriate Integer -- type, use New to allocate, and removed GNAT specific stuff. -- Notes: -- -- This test works if the word "constant" is removed -- -- The test also works if the value is less than 200_000_000 -- Indexing element also works with computed index Size : constant := 210_000_000; type Big_Int is range 0 .. Size; type Big_T is array (Big_Int range 1 .. Size) of aliased Float; type Big_A is access Big_T; Big : Big_A; -- function GetSomeMemory (X : Integer) return Big_A; -- pragma Import (C, GetSomeMemory, "malloc"); begin -- Big := GetSomeMemory (Size*4 + 16); -- This seems to work OK for now Big := new Big_T; Text_IO.Put_Line ("First element attribute " & Big_Int'Image (Big_T'First)); Text_IO.Put_Line ("Last element attribute " & Big_Int'Image (Big_T'Last)); Text_IO.Put_Line ("Address of first element is " & System.Storage_Elements.Integer_Address'Image( System.Storage_Elements.To_Integer(Big (Big_T'First)'Address))); Text_IO.Put_Line ("Address of last element is " & System.Storage_Elements.Integer_Address'Image( System.Storage_Elements.To_Integer(Big (Big_T'Last)'Address))); Text_IO.Put_Line ("(Last element should be at higher address than first)"); declare J : Big_Int := Size; begin Text_IO.Put_Line ("Address of last element is " & System.Storage_Elements.Integer_Address'Image( System.Storage_Elements.To_Integer(Big (J)'Address))); end; Text_IO.Put_Line ("Writing to all elements in loop"); for I in Big_T'Range loop Big (I) := 0.0; end loop; Text_IO.Put_Line ("Writing to 'Last element"); --raised STORAGE_ERROR : stack overflow (or erroneous memory access): Big (Big_T'Last) := 0.0; -- Fails!!!!! end TestBig2;