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.1 required=5.0 tests=BAYES_00, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,18e0d6e2d3937639,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.196.232 with SMTP id ip8mr2757384pbc.6.1340356132763; Fri, 22 Jun 2012 02:08:52 -0700 (PDT) MIME-Version: 1.0 Path: l9ni6306pbj.0!nntp.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.alt.net!news.dizum.com!sewer-output!mail2news From: Anonymous Newsgroups: comp.lang.ada Subject: begin/end reducing memory consumption? Message-ID: Date: Fri, 22 Jun 2012 09:08:30 +0000 (UTC) Mail-To-News-Contact: abuse@dizum.com Organization: mail2news@dizum.com Date: 2012-06-22T09:08:30+00:00 List-Id: Hi all, I'm currently evaluating Ada as an alternative to C++ for scientific programming. I have a simple test program that within its main loop repeatedly calls the following procedure: procedure Propagate is Access_Temp : constant Access_Probability_Field := Access_New_Field; begin Access_New_Field.all := (others => (others => (others => 0.0))); for Nx in -Fringe_Index .. Fringe_Index loop -- Fringe_Index = about 50 for Ny in -Fringe_Index .. Fringe_Index loop for Ntheta in Angle_Index'Range loop -- Range = 0 .. 199 begin -- why do I need this? for W of Weight_Vectors (Ntheta) loop -- Weight_Vectors (Ntheta) is a Vector of type Ada.Containers.Vectors -- (Element_Type => Weight, Index_Type => Natural), where Weight is defined as -- subtype Pixel_Offset is Integer range -Max_Offset .. Max_Offset; -- type Weight is record -- Nx, Ny : Pixel_Offset; -- W : Long_Float; -- end record; for D_Index in Angular_Propagator'Range loop Access_New_Field (Nx + W.Nx, Ny + W.Ny, Ntheta + D_Index) := Access_New_Field -- (Nx, Ny + 1, Ntheta) (Nx + W.Nx, Ny + W.Ny, Ntheta + D_Index) + Access_Old_Field (Nx, Ny, Ntheta) * W.W * Angular_Propagator (D_Index); end loop; end loop; end; end loop; end loop; end loop; Access_New_Field := Access_Old_Field; Access_Old_Field := Access_Temp; end Propagate; Access_New_Field and Access_Old_Field are of type access Probability_Field, where type Probability_Field is array (Pixel_Index'Range, Pixel_Index'Range, Angle_Index'Range) of Long_Float; subtype Pixel_Index is Integer range -(Fringe_Index + Max_Offset) .. (Fringe_Index + Max_Offset); my main loop looks like this: Access_New_Field := new Probability_Field; Access_Old_Field := new Probability_Field; for K in 1 .. No_Iterations loop Put_Line ("Iteration " & Integer'Image (K)); Propagate; end loop; What I don't get is that if I comment out the above "begin/end" lines, then memory usage increases with No_iterations and for No_iterations = 8 reaches about 550 MB. Including begin/end reduces memory usage to 37MB (then independent of No_iterations, as it should be). For what it's worth, I'm using the following compiler flags (with GNAT GPL 2011 on Mac OS X 10.7.4, 2010 MacBook Pro): gnatmake -o Main Main -P"/Users/sebastian/Documents/Studium/Research/hard-disk-disorder/lattice-propagator/release.gpr" -g -cargs -gnatq -gnatQ -bargs -largs gcc -c -gnatQ -O3 -gnatp -gnat2012 -g -gnatq -gnatQ -I- -gnatA [�]/Main.adb gcc -c -gnatQ -O3 -gnatp -gnat2012 -g -gnatq -gnatQ -I- -gnatA [�]/lattice_propagator.adb gcc -c -gnatQ -O3 -gnatp -gnat2012 -g -gnatq -gnatQ -I- -gnatA [�]/geometry.adb gnatbind -E -static -I- -x [�]/obj/main.ali gnatlink [�]/obj/main.ali -g -o [�]/build/Main Is this expected behaviour? If yes, could someone please explain what's going on internally? Best regards, Sebastian