|
-
June 9th, 2006, 06:30 PM
#1
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?
-
June 9th, 2006, 06:35 PM
#2
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);
-
June 9th, 2006, 07:46 PM
#3
Re: What To Use Instead Of Iterators
 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
-
June 12th, 2006, 11:42 PM
#4
Re: What To Use Instead Of Iterators
Well what I really want to know, is what I can use instead of:
-
June 13th, 2006, 01:01 AM
#5
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.
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
-
June 13th, 2006, 01:21 AM
#6
Re: What To Use Instead Of Iterators
 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.
-
June 13th, 2006, 07:47 AM
#7
Re: What To Use Instead Of Iterators
 Originally Posted by Rehorav
Well what I really want to know, is what I can use instead of:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|