Re: Do I really have to use an array?
On Jan 25, 1:38 am, Salt_Peter <pj_h...@yahoo.com> wrote:
On Jan 24, 3:15 pm, mike3 <mike4...@yahoo.com> wrote:
Your code uses integer everywhere instead of std::size_t
(or size_type) to track length.
Could these conversions actually cost as much as the entire
multiplication
loop?
Which loop? Does a conversion cost nothing? no.
It depends on which conversion. Conversions between integer
types, or between pointers, as long as no multiple inheritance
or virtual base classes are involved, typically have no runtime
cost.
I'm trying to figure out how you are 'managing' your elements,
i see a std::vector of pointers and std::auto_ptrs that are
being released() to transfer ownership. Thats very strange to
say the least. Any reason you aren't using boost::shared_ptr?
Those are copyable and assignable.
But copying them and assigning them has a very definite runtime
penalty. Not usually an issue, but since he's addressing a
performance problem.
There is one case where std::vector is significantly slower than
an array: creation and destruction. If he's creating a lot of
small, short lived vectors, that could slow things down. As an
alternative to array, he might want to look into boost::array.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34