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!w37g2000prg.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Table of pointers question Date: Fri, 25 Sep 2009 10:12:42 -0700 (PDT) Organization: http://groups.google.com Message-ID: <71e6fb97-e9bb-410a-bc3a-442e9248a4e0@w37g2000prg.googlegroups.com> 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 1253898762 13753 127.0.0.1 (25 Sep 2009 17:12:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 25 Sep 2009 17:12:42 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w37g2000prg.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:8471 Date: 2009-09-25T10:12:42-07:00 List-Id: On Sep 25, 9:52=A0am, bj=F6rn lundin wrote: > On 24 Sep, 03:34, Adam Beneschan wrote: > > > 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. > ..... > >=A0Also, 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. > > Is this true? Should one not expect the compiler to figure that out, > so what is shuffled > around, and memory allocated for, is for pointers, and not their > content? > > Or do I have too much faith in compilers Either you have way, way, way too much faith in compilers, or else we're not on the same page. If I have an array type Data_Record is ... something with a few hundred bytes in it end record; type Data_Array is array (natural range <>) of Data_Record; Arr : Data_Array (1 .. 1000); and I write an exchange sort that includes this code to do the exchange: Temp : Data_Record; ... Temp :=3D Arr (I); Arr (I) :=3D Arr (J); Arr (J) :=3D Temp; it will move several hundred bytes around, three times. If you're suggesting that the compiler should generate code to avoid this by exchanging pointers instead---well, then you're basically asking the compiler to figure out what algorithm the programmer is writing and replace it with something it thinks is a better algorithm. Which is not only impossible in practice, it would be incredibly rude even if it were possible. Compilers can be expected to do some optimization, but not to rewrite the program for you. If your frame of reference is a language (like Lisp) where everything is implemented as a pointer, then I could see how your comment might make sense. But Ada is not that kind of language. Ada will give you pointers if you tell it you want pointers, but (generally) not if you don't. -- Adam