CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2005
    Posts
    281

    What To Use Instead Of Iterators

    Ok, Iterators seem to slow the performance down far too much in applications. I don't know of any way to get around them. Can someone give me a suggestion on what I can use instead of iterators?

  2. #2
    Join Date
    Aug 2005
    Location
    Netherlands, The
    Posts
    2,184

    Re: What To Use Instead Of Iterators

    iteration is the fastest method for looping trough the memory(if you do it right)

    Code:
    int* data = malloc(sizeof(int) * 10);
    int set = 10;
    for(int* iter = data + 10; iter >= data; --iter)
     *iter = --set;
    free(data);

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: What To Use Instead Of Iterators

    Quote Originally Posted by Rehorav
    Ok, Iterators seem to slow the performance down far too much in applications.
    An iterator is a concept, not a type. So what you're saying doesn't really make sense.

    For example, pointers are random access iterators, so what do you mean by "iterators"? Pointers? A vector::iterator? A std::list::iterator? A map::iterator? Your own custom iterator?

    Regards,

    Paul McKenzie

  4. #4
    Join Date
    Nov 2005
    Posts
    281

    Re: What To Use Instead Of Iterators

    Well what I really want to know, is what I can use instead of:

    Code:
    n=0 ; n<5 ; n++

  5. #5
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: What To Use Instead Of Iterators

    see As Paul Suggest you that An iterator is a concept, not a type. Show what u mean by all of this things .if you directly want to perform some operation . use Vector or List what ever you want. you can use Recursion which is pretty fast.But you have to handle this in a very efficient manner.

    Code:
    n=0 ; n<5 ; n++
    what is this . if i put a for with braces it makes a for loop . and simply writing this is a Error like n++ doesn't have a semicolon. Second what ever state ment you write a loop if will execute till then loop condition is true . but what about your this lines is it going to serve something good for you. don't think soo.

    Thanx

    Thanx

  6. #6
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128

    Re: What To Use Instead Of Iterators

    Quote Originally Posted by Rehorav
    Ok, Iterators seem to slow the performance down far too much in applications. I don't know of any way to get around them. Can someone give me a suggestion on what I can use instead of iterators?
    Code:
    for(n=0 ; n<5 ; n++)
    {
    //...
    }
    There is nothing wrong or any performance issue with iteration using for-loop. I don't think you can do anything that is faster than the for-loop.

    One reason that it becomes a performance issue would be because you are writing the code to search through a very long array. If that is the case, you are approaching the problem incorrectly because there are many methods/algorithms that are well-suited for this task. For example, you can use binary search in a sorted array, hash-table, etc.
    quoted from C++ Coding Standards:

    KISS (Keep It Simple Software):
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.

    Avoid magic number:
    Programming isn't magic, so don't incant it.

  7. #7
    Join Date
    Apr 1999
    Posts
    50

    Re: What To Use Instead Of Iterators

    Quote Originally Posted by Rehorav
    Well what I really want to know, is what I can use instead of:

    Code:
    n=0 ; n<5 ; n++
    You should be using ++n, not n++

    From the FAQ: http://www.codeguru.com/forum/showthread.php?t=231052

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured