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-7-bit Path: g2news2.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!news.skynet.be!195.238.0.222.MISMATCH!newsspl501.isp.belgacom.be!tjb!not-for-mail Date: Mon, 11 May 2009 14:14:03 +0200 From: Olivier Scalbert User-Agent: Thunderbird 2.0.0.21 (X11/20090318) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Allocation question References: <4a07fc7a$0$2855$ba620e4c@news.skynet.be> <54897f26-0d3f-421e-9426-1822a531674e@p4g2000vba.googlegroups.com> In-Reply-To: <54897f26-0d3f-421e-9426-1822a531674e@p4g2000vba.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4a081676$0$2850$ba620e4c@news.skynet.be> Organization: -= Belgacom Usenet Service =- NNTP-Posting-Host: e127b29e.news.skynet.be X-Trace: 1242044022 news.skynet.be 2850 87.65.150.40:56588 X-Complaints-To: usenet-abuse@skynet.be Xref: g2news2.google.com comp.lang.ada:5758 Date: 2009-05-11T14:14:03+02:00 List-Id: 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 > type Image_T (Width, Height : Natural := 0) is private; > private > type Data_T is array(Positive range <>, Positive range <>) of > Color_T; > type Data_Access_T is access Data_T; > type Image_T (Width, Height : Natural) is > new Ada.Finalization.Controlled with record > Data : Data_Access_T; > end record; > overriding procedure Initialize (Object : in out Image_T); -- > allocates > overriding procedure Adjust(Object : in out Image_T); -- duplicates > Data.all? > overriding procedure Finalize(Object : in out Image_T); -- > deallocates > end Image; > > with Image; > declare > Im1 : Image.Image_T (1 .. 1024, 1 .. 1024); -- calls Initialize > which allocates > Im2 : Image.Image_T (0, 0); -- calls Initialize which does nothing > begin > Im2 := 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 Ada.Text_IO.Put("Initialize"); -- What shall I put here ? end Initialize; Olivier.