CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557

    Clearing ::std::vector<float>

    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?

    Code:
    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)
    You're gonna go blind staring into that box all day.

  2. #2
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: Clearing ::std::vector<float>

    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?

  3. #3
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557

    Re: Clearing ::std::vector<float>

    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.
    You're gonna go blind staring into that box all day.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured