Click to See Complete Forum and Search --> : Clearing ::std::vector<float>


dude_1967
July 28th, 2005, 05:03 AM
Hi Gurus,

A real quickie here...

In the given context below, is calling the member function clear enough to clear ::std::vector<float> such that calling size() returns zero?



bool c_ieee488_LeCroy_Waverunner_LT264::Waveform(const int ch, ::std::vector<float>& data) const
{
// Clear the result data vector.
data.clear();

// Build the command string.
// Go on to call resize() and collect the acquired data in the vector.



Thanks ::pow(10.0, 6.0);
(That means thanks a million)

NMTop40
July 28th, 2005, 05:21 AM
Yes, it will empty the container logically but not necessarily physically, i.e. you cannot guarantee it will free any memory.

But why not call resize() to the new size right at the start then start filling it will values?

dude_1967
July 28th, 2005, 05:33 AM
Oh, that's a goog idea, thanks.

Instead of calling clear(), reserve(...) and using push_back(...) to manipulate the vector, I can use resize() and subsequently operator[](...).

That makes it easier and results in compacter code.

Sincerely, Chris.