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: g2news1.google.com!postnews.google.com!b1g2000yqg.googlegroups.com!not-for-mail From: george.priv@gmail.com Newsgroups: comp.lang.ada Subject: Re: Performance of element access in Vector Date: Wed, 21 Jan 2009 11:25:04 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <0a8baaf0-19f7-40c0-a041-884e93fa7020@w39g2000prb.googlegroups.com> <1fp3pbmn4q3o5.1b0fk6lircbld.dlg@40tude.net> <4c38e681-3996-4ce9-ad33-6f7bd790fdbf@u18g2000pro.googlegroups.com> NNTP-Posting-Host: 151.196.71.114 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1232565904 515 127.0.0.1 (21 Jan 2009 19:25:04 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 21 Jan 2009 19:25:04 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b1g2000yqg.googlegroups.com; posting-host=151.196.71.114; posting-account=VnNb3AoAAACTpRtCcTrcjmPX7cs92k1Q User-Agent: G2/1.0 X-HTTP-Via: 1.1 SPARKS X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:3474 Date: 2009-01-21T11:25:04-08:00 List-Id: On Jan 21, 3:52=A0am, Maciej Sobczak wrote: > 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. > Letting vector grow causes unpredictable run-time penalties. Inserting/deleting elements can be time consuming. If worse come to worse these can be addressed in totally different programming paradigm foreign to C++. > 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. > Agree > 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. > If you just try to get away from C++ paradigm you can find other ways to address these issues with raw arrays. Think in functional programming framework for a change. George > -- > Maciej Sobczak *www.msobczak.com*www.inspirel.com > > Database Access Library for Ada:www.inspirel.com/soci-ada