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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,345a8b767542016e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-03-17 20:09:38 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: kcline@optelnow.net (Kevin Cline) Newsgroups: comp.lang.ada Subject: Re: memory leakages with Ada? Date: 17 Mar 2002 20:09:38 -0800 Organization: http://groups.google.com/ Message-ID: References: <3c90af1e@news.starhub.net.sg> <3c91bfa3.1987537@news.demon.co.uk> <3C921A81.9060708@mail.com> NNTP-Posting-Host: 24.219.81.150 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1016424578 16612 127.0.0.1 (18 Mar 2002 04:09:38 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 18 Mar 2002 04:09:38 GMT Xref: archiver1.google.com comp.lang.ada:21391 Date: 2002-03-18T04:09:38+00:00 List-Id: "Chad R. Meiners" wrote in message news:... > "Kevin Cline" wrote in message > > Dereferencing nil is just as fatal to program execution. The only > advantage > > is that it is more easily debugged because the crash is immediate. > > Any code that keeps invalid pointers around, whether null or not, is > > poorly crafted. Good programmers don't much care about the state > > of a pointer variable after delallocation because the variable > > is either going to be reassigned immediately or is going out of scope. > > While it is true that dereferencing a null pointer will raise a > constraint_error exception, exceptions can be handled gracefully and null > pointers can be guarded against. Pointers off to nowhere are very difficult > to detect in a general manner. > > Your assertion about good programmers not caring about the state of a > pointer, however, is false. For example, let's say we want to build a hash > table of complex objects. Why wouldn't I use one of the many fine generic implementations already available? > This can be accomplished via an array of pointers > to the given object type. Here is a case where we will want to reuse the > pointers (although not necessarily immediately) since we might delete and > add a bunch of objects throughout the program's lifetime. Here we can > clearly use the state of the pointers to hold valuable information about the > table. Is this use improper? No, this is actually a case where using > pointers is the right way to go about solving the problem. Other examples > of null pointers being useful are linked lists and tree data structures. Certainly it is, but in my experience the implementation of such fundamental data structures is a small part of application code, and not often the source of memory leaks since it's clear which code is responsible for deallocation. > > This is one of the many reasons why I like Ada. The designers did a very > good job with access types. I have never encountered a situation where I > felt I was being forced by the language to use a pointer improperly in the > six years I have been programming with it. I don't think there any languages that force one to use a pointer improperly. There are some languages where a pointer can be used improperly with less typing that is necessary in Ada. Ada makes the undesirable inconvenient. It forces the inexpert to ask questions of their betters, because without guidance they won't be able to appease the compiler. This can be a good thing.