c++ - How can I get the address of the buffer allocated by vector::reserve()? -
I have a standard standard vector for which I know the maximum size, but actual size will be different during use :
zero setup buffer (const size_t maxSize) {myVector.reserve (maxSize); } Zero addToBuffer (const value & amp; v) {myVector.push_back (v); If (myVector.size () == maxSize) {// Process data ... myVector.clear (); }}
However, in SetupBuffer, I have to get an indicator to start the data of myVector. I am using a third party library where I can find "Process Data ... "This indicator needs to be cached in order to use in calls made during the section.
zero setup buffer (const size_t maxSize) {MyVector.reserve (maximal); CachePtr (& amp; (myVector [0])); // does not work, obviously
I do not want to change the vector () on the front, because I want to use vector size (), which means that Number of elements added to vector
So, after the allocation (reserved), there is no way to get the pointer in vector buffer, but before that there is an element? I think the buffer is present (and will not run unless I limit the number of values pushed_back'd) .... Maybe this is not guaranteed?
The vector buffer will not be reserved after the call until you exceed the reserve capacity . Your problem is getting the pointer to the first element in a clear answer vector to push a single duplicate entry, get it to the pointer, and then remove it.
It would be a good way if the library accepts a funny rather than a pointer, which requires access to the buffer, when you could say to access the buffer - some buffer The material was, until you were able to get to the brain. However, I know that you do not have the luxury of writing the library again.
Comments
Post a Comment