Talk:Sieve of Eratosthenes (C Plus Plus)

From LiteratePrograms
Jump to: navigation, search

Your sieve_of_eratosthenes() returns the vector by value, which is inefficient because it involves copying the entire contents of the vector to the one in the main() function. This may lead to misleadingly poor performance being measured in the test.

Perhaps you can have the sieve_of_eratosthenes() function take an additional parameter which is an iterator, and then it write the primes to the container pointed to by the iterator. (This would assume that the container allocated by the caller is large enough, of course; and the necessary size may be difficult for the caller to determine.) Alternately, you may have sieve_of_eratosthenes() take in a vector &, a reference to a vector allocated by the caller, and then add primes to the end of it. --Spoon! 15:20, 8 January 2008 (PST)

hijacker
hijacker
hijacker
hijacker