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,7343d4a788a9b1a5 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news3.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!peer-uk.news.demon.net!kibo.news.demon.net!mutlu.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: How-to on using the adacl-gc packages Date: Mon, 15 May 2006 21:13:06 +0100 Organization: Pushface Message-ID: References: <820e1$44676a08$52ae05e3$31697@news.versatel.net> <1147631169.665365.244810@i40g2000cwc.googlegroups.com> <1147675928.810016.197550@i39g2000cwa.googlegroups.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1147723987 3866 62.49.19.209 (15 May 2006 20:13:07 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Mon, 15 May 2006 20:13:07 +0000 (UTC) Cancel-Lock: sha1:0BBWS7y2K+s7/mZm6jDGBPY13c4= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) Xref: g2news2.google.com comp.lang.ada:4269 Date: 2006-05-15T21:13:06+01:00 List-Id: "Martin Krischik" writes: > I know at least one memory allocation problem where I have not yet > found a solution for - no matter how much engineering I have put into > the problem: > > task type T; > type T_Access is access T; > > ... > > X : T_Access := new T; What I do in ColdFrame is (with a bit of concatenation and elision) type Instance (<>) is new ---- with private; type Handle is access all Instance; private task type T (This : access Instance) is ----- entry -----; end T; type T_P is access T; procedure Free is new Ada.Unchecked_Deallocation (T, T_P); type Instance is new ----- with record The_T : T_P; ----- end record; procedure Free is new Ada.Unchecked_Deallocation (Instance, Handle); procedure Delete (This : in out Handle) is ----- begin ----- abort This.The_T.all; Free (This.The_T); ----- Free (This); end Delete; which has caused us no problems (GNAT, NT, Linux, MacOS, VxWorks)[1]; but I'm always prepared to be told I'm wrong. A while back AdaCore pointed me towards LRM 13.11.2(9): Free(X), when X is not equal to null [...] deallocates the storage occupied by the object designated by X. [...] There is one exception: if the object being freed contains tasks, the object might not be deallocated. It's not clear to me quite what 'contains tasks' means. From a position of ignorance, I could argue that The_T.all doesn't _contain_ a task, it _is_ a task. > The last I read only recently here was: task types are small - don't > bother deallocating them. Anybody got any better advice? It all depends how often you do it and what your platform's memory availability is! On VxWorks (5.4, PowerPC) you are stuck with the physical memory ... [1] except when people called Delete from the task that was to be deleted. I catch this now.