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,6d4eecb82d078fd6 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!s1g2000prd.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Exception_Access_Violation Date: Fri, 22 May 2009 09:38:07 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <3f465d87-0fc9-415d-a60b-72a0d744dce1@h23g2000vbc.googlegroups.com> <77f52dF1gt12kU1@mid.individual.net> <669e505c-f111-47b9-8cc5-ca1815161c53@s20g2000vbp.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1243010287 31008 127.0.0.1 (22 May 2009 16:38:07 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 22 May 2009 16:38:07 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s1g2000prd.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:5982 Date: 2009-05-22T09:38:07-07:00 List-Id: On May 20, 8:30=A0am, mhamel...@yahoo.com wrote: > Problem solved! =A0Thanks for all the help, especially the pointer to > Debug_Pools. =A0The problem was that instead of allocating one node at a > time, I was allocating an array of nodes at once. =A0Deallocating nodes > allocated from an array allocation is apparently bad juju. =A0I don't > understand it, but can work around it. The Ada language rules say that you cannot call Unchecked_Deallocation on something that has not been allocated with "new". This isn't any different from other languages. In C, for example, the man page for free() says "free() frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc(), calloc () or realloc()." In other words, you can't just "deallocate" any chunk of memory you feel like; it has to be an area of memory that was previously allocated by the storage manager---the whole thing, not some part of it. The simple reason for this is that the storage manager that handles allocations and deallocations expects things to be done this way, and it may keep information about the memory areas that have been allocated, or close to the memory areas. For example, when you allocate a block of memory, the storage manager may reserve a couple words just *below* that block of memory to keep its own control information. (It won't necessarily do this, but it might.) Trying to deallocate something that the storage manager doesn't know about, or trying to deallocate something that has already been deallocating, is about the worst thing you can do. It is likely to screw up the storage manager's data structures, and often will lead to bugs in the program that won't be detected until much later in the execution, and bugs like that are the most difficult ones to track down---trust me, I've been there, especially back when I was working in C. So don't mess with it. If you really want to reuse individual nodes, you probably want to write your own deallocation and allocation routines for nodes, instead of relying on Unchecked_Deallocation and "new". The deallocation routine would add a node to a free list; the allocation routine would then reuse a node from the free list if there are any. -- Adam