我正在开发一个 C++ 应用程序,我需要将 std::set 的内容复制到 std::deque。类似于我在我的应用程序中所做的事情如下。(这是简化版)
class A
{
public:
A(){};
~A() {};
void UpdateDataSet(std::set<C>& _setData);
private:
std::deque<C> deque_Data;//contains ohlc data for the symbol
};
void A::UpdateDataSet(std::set<C>& _setData)
{
std::set<C>::iterator itrSet = _setData.begin();
std::set<C>::iterator itrSetEnd = _setData.end();
while(itrSet != itrSetEnd)
{
deque_Data.push_back(*itrSet);
++itrSet;
}
}
int main()
{
A* pA = new A();
std::set<C> setData;
C mC1(5,10);
C mC2(10,20);
C mC2(30,40);
C.insert(mC1);
C.insert(mC2);
C.insert(mC3);
pA->UpdateDataSet(setData);
return 0;
}
这里 C 是一个包含两个整数的类。上面的代码按我的预期工作得很好。但问题是当我使用 valgrind memcheck 对我的代码进行分析时,它指出了代码块附近可能丢失的一些数据
deque_Data.push_back(*itrSet);
valgrind 输出如下。
==3469== 1,032,640 bytes in 180 blocks are possibly lost in loss record 1,337 of 1,346
==3469== at 0x4006355: operator new(unsigned int) (vg_replace_malloc.c:214)
==3469== by 0x46B92AF: __gnu_cxx::new_allocator<C*>::allocate(unsigned int, void const*) (new_allocator.h:88)
==3469== by 0x46B92E7: std::_Deque_base<C, std::allocator<C> >::_M_allocate_map(unsigned int) (stl_deque.h:424)
==3469== by 0x46B94F9: std::deque<C, std::allocator<C> >::_M_reallocate_map(unsigned int, bool) (deque.tcc:750)
==3469== by 0x46B960B: std::deque<C, std::allocator<C> >::_M_reserve_map_at_back(unsigned int) (stl_deque.h:1444)
==3469== by 0x46B96C5: std::deque<C, std::allocator<C> >::_M_push_back_aux(C const&) (deque.tcc:348)
==3469== by 0x46B9822: std::deque<C, std::allocator<C> >::push_back(C const&) (stl_deque.h:1045)
==3469== by 0x46B6B09: A::UpdateDataSet(std::set<C, std::less<C>, std::allocator<C> >&)
有人可以帮我找出这里的内存问题。这个 valgrind 输出真的意味着内存泄漏吗?