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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bb7cc916bd63ab43 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!u18g2000pro.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Performance of element access in Vector Date: Wed, 21 Jan 2009 00:52:06 -0800 (PST) Organization: http://groups.google.com Message-ID: <4c38e681-3996-4ce9-ad33-6f7bd790fdbf@u18g2000pro.googlegroups.com> References: <0a8baaf0-19f7-40c0-a041-884e93fa7020@w39g2000prb.googlegroups.com> <1fp3pbmn4q3o5.1b0fk6lircbld.dlg@40tude.net> NNTP-Posting-Host: 128.141.45.219 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1232527926 13686 127.0.0.1 (21 Jan 2009 08:52:06 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 21 Jan 2009 08:52:06 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: u18g2000pro.googlegroups.com; posting-host=128.141.45.219; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:4432 Date: 2009-01-21T00:52:06-08:00 List-Id: On 20 Sty, 23:07, george.p...@gmail.com wrote: > Unlike C++ for simple objects I don't see advantage of using vectors > vs. arrays in Ada.=A0Only that it provide uniform ways to traverse > through all containers? =A0Anything else I am missing? Growing/shrinking. Vector can be built by appending without prior knowledge of the element count. Think about reading data from files, databases, etc. This is probably the most useful feature of this data structure. Of course, it is also useful for element removal - Vector automatically tracks its size. When compared to this, messing around with explicit length (i.e. how many elements are "used" in the raw array) management is too error prone. In other words, Vector is not only dynamic, it is also self-conscious. In C++ the only real reason to frown upon vector is in high-integrity or constrained environments because of the dynamic memory issues. Otherwise, in a general-purpose programming, it is superior to raw arrays in 95% of cases and recommended as a "default" array-like container. It also guarantees continuous storage, which makes it a very nice direct I/O buffer - although this is not widely recognized. For someone coming from the C++ universe the inability of Vectors in Ada to do all these things with comparable performance is disappointing and it looks like the notion of reference as a first- class program entity is crucial here. -- Maciej Sobczak * www.msobczak.com * www.inspirel.com Database Access Library for Ada: www.inspirel.com/soci-ada