title: c++ vector construct with given memory
body: <p>I'd like to use a std::vector to control a given piece of memory. First of all I'm pretty sure this isn't good practice, but curiosity has the better of me and I'd like to know how to do this anyway.</p>
  
  <p>The problem I have is a method like this:</p>
  
  <pre><code>vector&lt;float&gt; getRow(unsigned long rowIndex)
  {
      float* row = _m-&gt;getRow(rowIndex); // row is now a piece of memory (of a known size) that I control
      vector&lt;float&gt; returnValue(row, row+_m-&gt;cols()); // construct a new vec from this data
      delete [] row; // delete the original memory 
      return returnValue; // return the new vector 
  }
  </code></pre>
  
  <p>_m is a DLL interface class which returns an array of float which is the callers responsibility to delete. So I'd like to wrap this in a vector and return that to the user.... but this implementation allocates new memory for the vector, copies it, and then deletes the returned memory, then returns the vector. </p>
  
  <p>What I'd like to do is to straight up tell the new vector that it has full control over this block of memory so when it gets deleted that memory gets cleaned up. </p>
  
  <p><strong>UPDATE</strong>: The original motivation for this (memory returned from a DLL) has been fairly firmly squashed by a number of responders :) However, I'd love to know the answer to the question anyway... Is there a way to construct a std::vector using a given chunk of pre-allocated memory T* array, and the size of this memory?</p>