Lets say I have a char* allocated from a custom memory pool and filled with necessary data. I use that char* in the assign method of std::string class and make sure move varient is called by using std::move.
void DoWork(char* my_pool_allocated_buffer) {
std::string s;
s.assign(std::move(my_pool_allocated_buffer));
//do some work with s
}
I have two questions.
- At the end of the method, would the std::string destructor try to delete my_pool_allocated_buffer it aquired through assign? Documentation says it will only delete memory it allocated through its own allocator however.
- After method exit, the my_pool_allocated_buffer will be freed by its pool. Does the use of std::move has any affect on this? (assuming the pool does not care about the actual data the buffer holds).