Kim*_*imi 1 c++ scope vector std
目前我正在研究这个C++源代码.我不是C++开发者.
void SomeClass::SomeMethod() const
{
vector<Thing> things(count);
...
//Elements are added or replaced in things but no deallocation of things here
}
Run Code Online (Sandbox Code Playgroud)
SomeMethod
被称为很多次.任何人都可以确认没有泄漏,things
只分配一次,参考将不胜感激.
在vector
创建每次您输入的功能和销毁(销毁所有对象,并释放所有的内存),当它离开范围(当函数结束).没有泄漏,但是如果经常调用该函数,则会有很多分配和解除分配.
你有2个解决方案来避免这种情况:
mutable
以允许通过const
方法更改),