Re: vector acces by index/iterator

From: SaltPeter (SaltPeter_at_Jupiter.sys)
Date: 07/20/04


Date: Tue, 20 Jul 2004 10:09:06 -0400


"Richard Herring" <junk@[127.0.0.1]> wrote in message
news:NH0bNVc2tP$AFwSQ@baesystems.com...
> In message <kF3Lc.16349$Gf7.528126@news20.bellglobal.com>, SaltPeter
> <SaltPeter@Jupiter.sys> writes
> >
> >"DaKoadMunky" <dakoadmunky@aol.com> wrote in message
> >news:20040719222806.10778.00001547@mb-m25.aol.com...
> [...]
>
> >> My thinking is that since both an array and a vector use a single
> >contiguous
> >> block of memory and that to access an individual element in either an
> >array or
> >> vector requires the same pointer arithmetic that the performance would
be
> >> comparable in the presence of inlining for the vector operator[].
> >
> >The standard guarentees that *any* element of the vector container is
> >accessed using a constant time period (so any element is accessed with
the
> >same access period as the container's first element). There is a
> >misconception out there that a vector is like a list where each element
> >pointing to the next. This is not the case.
>
> It's not a misconception I've noticed. YMMV.
>
> > Vectors use random iterators.
> >These aren't available to either the array or std::list.
>
> Arrays have random-access iterators. They're called pointers.
>
> A {random-access, bidirectional, forward, input, output} iterator is
> anything satisfying the requirements of {random-access, bidirectional,
> forward, input, output} iterator (24.1). A pointer into an array does
> everything that's needed for a random-access iterator, therefore it is
> one. As witness the fact that many implementations of std::vector use
> raw pointers as their iterators.
>
> >And the array
> >doesn't even have a conception of what an iterator is.
>
> The only iterator-related things that arrays lack are the functions
> which return them.

Yep, well i deserved that response.

What i was refering to was the support for the said iterators as your last
comment mentions. In other words, an array doesn't have an end(). :)

>
> [...]
>
> --
> Richard Herring



Relevant Pages

  • Re: Sorting records using sort()
    ... We have an array of n*m bytes. ... >> The trouble with writing iterators for this problem is that he needs it ... We create a proxy class and let the iterator return proxy objects. ... that is used only inside the iterator, it sets the data pointer to point ...
    (comp.lang.cpp)
  • Re: Assigning generator expressions to ctype arrays
    ... inefficient to have to create a temp array. ... But necessary to work with blank box iterators. ... Since slice assignment does not use temporary arrays now, that augmentation should be conditional on the source type being a non-sequence iterator. ...
    (comp.lang.python)
  • Re: Container library (continued)
    ... beat in the container arena imo. ... list or array C interface has to come first. ... I think you could use next / prev pointers as iterators. ...
    (comp.lang.c)
  • Re: Heres a Python-like range() for JavaScript. Is it new?
    ... I think it easier to slice an array than to code a function. ... Allocating memory for an array object of arbitrary length and then keeping that array in memory just to use its `length` is silly, ... similar concerns were the reasons iterators were implemented in newer versions of JavaScript. ... Yes, `this` references global object, since `call` was invoked with first argument being `undefined`. ...
    (comp.lang.javascript)
  • Re: [PHP] RecursiveArrayIterator
    ... Isn't that what garbage collection is for? ... is saying is Iterators dont bother creating a copy of the array, ... > dangling in memory. ... SPL iterators do things differently and know only one ...
    (php.general)