Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ std::队列内存释放不起作用_C++_Memory Management_Memory Leaks_Stl - Fatal编程技术网

C++ std::队列内存释放不起作用

C++ std::队列内存释放不起作用,c++,memory-management,memory-leaks,stl,C++,Memory Management,Memory Leaks,Stl,我有一个基本类,我从一个线程推送成员,从另一个线程弹出。但当我使用内存泄漏验证程序调试时,我发现内存没有释放,验证程序显示泄漏问题处于推送阶段。在我的类中,我有一个数组,但它不是动态的 My_class{ int my_var1; int my_var22; int my_array[100000]; My_class& operator=(const My_class& old){ if(this!=&old){

我有一个基本类,我从一个线程推送成员,从另一个线程弹出。但当我使用内存泄漏验证程序调试时,我发现内存没有释放,验证程序显示泄漏问题处于推送阶段。在我的类中,我有一个数组,但它不是动态的

My_class{

    int my_var1;
    int my_var22; 
    int   my_array[100000];

    My_class& operator=(const My_class& old){

    if(this!=&old){

        var1=old.var1;
        var2=old.var2;
        memcpy(my_array,old.my_array,size)  //size is fixed so it is same as 100000     
    }

    My_class(const My_class &copy){

      *this=copy;
    }
};

 //here i am reading data from udp and copy from another array to my var1;
My_class var1;
My_class var2;
int udp_array[];

//thread one

while(hasPendingdata()){

udp_array.fill();
//my_array is filled after loop
} 
//than 

mem_cpy(var1.my_array,udp_array,size);

my_mutex.lock();

   std::my_queue.push(var1);

my_mutex.unlock();


//thread 2
my_mutex.lock();

  var2=my_queue.front();
  my_queue.pop();
my_mutex.unlock();

如果移除了赋值操作符,复制构造函数,让编译器生成的函数完成任务,那么一切都会更容易。不要在C++中使用MeMCPY,更喜欢STD::CopyAc随@ @ JuangopaZa的注释,这就是它的一般规则。另一方面,如果您必须编写自己的赋值运算符、构造函数等;更愿意根据复制和交换的复制或搜索来编写assignment运算符idiom@juanchopanza谢谢,但它没有work@barp这只是一个建议,简化代码并缩小bug搜索空间。您的问题很可能与如何从不同线程访问队列有关。