comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Table of pointers question
Date: Wed, 23 Sep 2009 18:34:17 -0700 (PDT)
Date: 2009-09-23T18:34:17-07:00	[thread overview]
Message-ID: <e305ee6e-cf9e-4672-ac5d-4f528ce37c06@h14g2000pri.googlegroups.com> (raw)
In-Reply-To: utflb5p8871f6p2531cr81tkdteacm786a@4ax.com

On Sep 23, 5:47 pm, Rob Solomon <use...@drrob1-noreply.com> 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.  Note that the variables are more like Modula-2 syntax as I am
> very comfortable with that.  And it is easier to type.

ItMayBeEasierToTypeButItSureAsHellIsntEasierToReadAndIfYouCareAboutEaseOfTypingMoreThan
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.  The example does not define that.
>
> How does the line:
> EntryPointerList(NumberOfEntries) := 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



  reply	other threads:[~2009-09-24  1:34 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-24  0:47 Table of pointers question Rob Solomon
2009-09-24  1:34 ` Adam Beneschan [this message]
2009-09-24  6:39   ` tmoran
2009-09-25 16:52   ` björn lundin
2009-09-25 17:12     ` Adam Beneschan
2009-09-24  2:00 ` (see below)
2009-09-24  3:46 ` Jeffrey R. Carter
2009-09-24  6:59 ` Georg Bauhaus
2009-09-24  7:06   ` Georg Bauhaus
2009-09-24 14:55   ` Adam Beneschan
2009-09-26 13:45     ` Rob Solomon
2009-09-24  6:59 ` Stephen Leake
2009-09-26 13:50   ` Rob Solomon
     [not found] ` <3cadnZif2YjGbyfXnZ2dnUVZ_tmdnZ2d@earthlink.com>
2009-09-24 12:49   ` Robert A Duff
2009-09-26 13:36   ` Rob Solomon
2009-09-26 14:51     ` John B. Matthews
     [not found]     ` <3YSdnY7SXPNd_yPXnZ2dnUVZ_sydnZ2d@earthlink.com>
2009-09-26 18:58       ` Rob Solomon
2009-09-26 21:00       ` Georg Bauhaus
2009-09-27  5:53     ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox