We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// 删除 [first, last) 的元素 template <class CharType, class CharTraits> typename basic_string<CharType, CharTraits>::iterator basic_string<CharType, CharTraits>:: erase(const_iterator first, const_iterator last) { if (first == begin() && last == end()) { clear(); return end(); } const size_type n = end() - last; iterator r = const_cast(first); char_traits::move(r, last, n); size_ -= (last - first); return r; } 考虑last到last+n的长度若小于last-first,这个函数只是将[first, last)范围内的元素移动到[first]的位置,但是并没有释放last,到末尾范围内的内存空间,是否最造成内存泄露问题
The text was updated successfully, but these errors were encountered:
没有问题。通常来说很难只释放一段动态分配的内存的其中一部分, C/C++ 标准没有提供任何能保证这么做的工具。
Sorry, something went wrong.
No branches or pull requests
// 删除 [first, last) 的元素
template <class CharType, class CharTraits>
typename basic_string<CharType, CharTraits>::iterator
basic_string<CharType, CharTraits>::
erase(const_iterator first, const_iterator last)
{
if (first == begin() && last == end())
{
clear();
return end();
}
const size_type n = end() - last;
iterator r = const_cast(first);
char_traits::move(r, last, n);
size_ -= (last - first);
return r;
}
考虑last到last+n的长度若小于last-first,这个函数只是将[first, last)范围内的元素移动到[first]的位置,但是并没有释放last,到末尾范围内的内存空间,是否最造成内存泄露问题
The text was updated successfully, but these errors were encountered: