I am using vector as an input buffer...
recv = read(m_fd, &m_vbuffer[totalRecv], SIZE_OF_BUFFER);
After it reads all data from the input buffer then it will put the data inside of the vector into the thread pool.
So I was trying to do clone the vector. I think I cannot just pass the pointer to the vector because of the new packets coming in and it overwrites the data inside of the vector.
However, I could not find a way to clone the vector. Please provide me a proper way to handle this. Also I will be very appreciated if you guys point out any problems using vectors as input buffer or tutorials related to this...
Vector, cloning: A fragment of DNA into which another DNA fragment can be integrated. Cloning vectors are used to introduce foreign DNA into host cells, where that DNA can be reproduced (cloned) in large quantities.
You can easily copy a vector using its copy constructor:
vector<T> the_copy(the_original); // or
vector<T> the_copy = the_original;
At the first, you may have to call recv with &m_vbuffer[0]
.
About cloning of vector, use copy().
#include <algorithm>
...
vector<char> m_vcopy;
m_vcopy.reserve(m_vbuffer.size());
copy(m_vbuffer.begin(), m_vbuffer.end(), m_vcopy.begin());
However, note that the element should not be reference. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With