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: a07f3367d7,aa14979d20ba3045 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!s16g2000vbp.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Allocation question Date: Mon, 11 May 2009 05:18:59 -0700 (PDT) Organization: http://groups.google.com Message-ID: <74e0fe4b-7da8-4808-b1f5-58551dca29b1@s16g2000vbp.googlegroups.com> References: <4a07fc7a$0$2855$ba620e4c@news.skynet.be> <54897f26-0d3f-421e-9426-1822a531674e@p4g2000vba.googlegroups.com> <4a081676$0$2850$ba620e4c@news.skynet.be> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1242044339 5970 127.0.0.1 (11 May 2009 12:18:59 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 11 May 2009 12:18:59 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s16g2000vbp.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:5761 Date: 2009-05-11T05:18:59-07:00 List-Id: Olivier Scalbert wrote on comp.lang.ada: > Ludovic Brenta wrote: > > Yes. Your image is on the stack. You can increase the size of the > > stack up to an operating-system-dependent maximum (see ulimit(1) on > > Unix-like systems) but there is always a limit. For potentially very > > large objects, I think the better approach is to allocate them on the > > heap. I would suggest you hide the allocation and deallocation inside > > a controlled object which you declare on the stack, e.g. > > > private with Ada.Finalization; > > package Image is > > =A0 =A0type Image_T (Width, Height : Natural :=3D 0) is private; > > private > > =A0 =A0type Data_T is array(Positive range <>, Positive range <>) of > > Color_T; > > =A0 =A0type Data_Access_T is access Data_T; > > =A0 =A0type Image_T (Width, Height : Natural) is > > =A0 =A0 =A0new Ada.Finalization.Controlled with record > > =A0 =A0 =A0 Data : Data_Access_T; > > =A0 =A0end record; > > =A0 =A0overriding procedure Initialize (Object : in out Image_T); -- > > allocates > > =A0 =A0overriding procedure Adjust(Object : in out Image_T); -- duplica= tes > > Data.all? > > =A0 =A0overriding procedure Finalize(Object : in out Image_T); -- > > deallocates > > end Image; > > > with Image; > > declare > > =A0 =A0Im1 : Image.Image_T (1 .. 1024, 1 .. 1024); -- calls Initialize > > which allocates > > =A0 =A0Im2 : Image.Image_T (0, 0); -- calls Initialize which does nothi= ng > > begin > > =A0 =A0Im2 :=3D Im1; -- calls Finalize (Im2) then Adjust (Im2) > > end; -- calls Finalize for both > > > You may also share image data between objects. > > > For even larger objects you can make Initialize, Adjust and Finalize > > much more sophisticated and store parts of the object on the heap and > > part on disk. You would do that only if you think you can beat the > > performance of your kernel's paging subsystem. > > > HTH > > > -- > > Ludovic Brenta. > > Thanks Ludovic. > > procedure Initialize (Object : in out Image_T) is > begin > =A0 =A0 =A0Ada.Text_IO.Put("Initialize"); > =A0 =A0 =A0-- What shall I put here ? > end Initialize; > > Olivier. Read the Object's Width and Height (the discriminants can be read like any other component). Allocate the Data_Array_T on the heap with the corresponding size. Assign the result to Object.Data. -- Ludovic Brenta.