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 Path: g2news2.google.com!postnews.google.com!h14g2000pri.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Table of pointers question Date: Wed, 23 Sep 2009 18:34:17 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: 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 1253756058 21818 127.0.0.1 (24 Sep 2009 01:34:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 24 Sep 2009 01:34:18 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h14g2000pri.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:8447 Date: 2009-09-23T18:34:17-07:00 List-Id: On Sep 23, 5:47=A0pm, Rob Solomon wrote: > I am working my way thru Ada As A Second Language by Norman Cohen (c) > 1996 > > This confuses me. > > It is a simple sorting routine that swaps pointers rather than the > data. =A0Note that the variables are more like Modula-2 syntax as I am > very comfortable with that. =A0And it is easier to type. ItMayBeEasierToTypeButItSureAsHellIsntEasierToReadAndIfYouCareAboutEaseOfTy= pingMoreThan BeingNiceToTheReaderWhyNotJustNameAllYourVariablesWithSingleLetters??? This has always been a bugaboo of mine. People whose native languages use Latin or Cyrillic or other alphabets are used to seeing spaces between words, and _ is unobtrusive enough look like a space to the eye, but jamming everything together takes that space away from us and makes things harder on the eyes. I cannot for the life of me understand why anyone would prefer that style. OK, I'm done ranting. > My question is that I would expect to have an array that contains the > data, and a second array that is an array of pointers to the 1st > array. =A0The example does not define that. > > How does the line: > EntryPointerList(NumberOfEntries) :=3D new DirectoryEntryType'(NewEntry) > ; > > Do what's needed? It finds some memory somewhere to store the DirectoryEntryType data. You don't need to know where. All you need to know is that EntryPointerList(NumberOfEntries) will point to it, and you go through that pointer to get to the data. The example above does declare an array of DirectoryEntryType, i.e. EntryList, but this array isn't used anywhere. Did Cohen really declare that variable, or did you add it yourself? Whether to use an array of DirectoryEntryType or an array of pointers is a design decision. The advantages of using an array of pointers is that a pointer is smaller than a DirectoryEntryType (and in a real- life application, it could be MUCH smaller), so if NumberOfEntries is, say, 15, allocating a fixed-size array of 1000 pointers and waiting until runtime to allocate 15 DirectoryEntryTypes takes a lot less memory than allocating 1000 DirectoryEntryTypes. Yeah, I know, memory is cheap and nobody cares any more about memory usage. But they should, since I'm sick of applications that use virtual memory wantonly and then use up all my computer's resources swapping like crazy so that I can't run anything else. Also, when you do the exchange, you're moving two pointers around rather than moving two DirectoryEntryTypes, which is a lot faster since the pointers are smaller. There may be other cases where you'd rather have an array of data than an array of pointers. But it would be very rare that you'd need both. If you have an array of pointers, you can index into that array to get to the data you need, so there's no reason to set up an array of data for you to index into. -- Adam