Group: comp.lang.c++
From: Juha Nieminen
Date: Sunday, April 13, 2008 1:57 PM
Subject: Re: Initialization of vectors in c++

Jerry Coffin wrote:
> As others have pointed out, the value is guaranteed to be zero.

Sometimes I feel this is counter-productive speedwise.

If I want to allocate a large array of, for example, integers and I
don't need for them to be initialized to anything (eg. because right
after the allocation I initialize them manually to some values), the
std::vector will uselessly go through the allocated array, initializing
every value with 0, right after which I go again through the vector and
initialize the values to something else. This is wasted time.

If I allocate the array with 'new', it won't do anything to it and it
will be much faster.

Safety Articles | Usenet Groups | 20lbs in 30 days