Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.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::bad_alloc_C++_C++11_Boost - Fatal编程技术网

C++ 一段时间后获得std::bad_alloc

C++ 一段时间后获得std::bad_alloc,c++,c++11,boost,C++,C++11,Boost,我有一段代码,运行在5倍的CrossValidiaton上,代码在每一倍上做相同的事情,但问题是;它在每一次折叠中都消耗了可交换的内存,而且似乎没有释放内存,你能告诉我问题出在哪里吗? 我得到的错误是: 在抛出“std::bad_alloc”的实例后终止调用 what():std::bad_alloc./run.sh:第3行:12014已中止 (核心倾倒)。/我的助推 代码是: #include <iostream> #include <boost/dynamic_bitset

我有一段代码,运行在5倍的CrossValidiaton上,代码在每一倍上做相同的事情,但问题是;它在每一次折叠中都消耗了可交换的内存,而且似乎没有释放内存,你能告诉我问题出在哪里吗? 我得到的错误是:

在抛出“std::bad_alloc”的实例后终止调用
what():std::bad_alloc./run.sh:第3行:12014已中止
(核心倾倒)。/我的助推

代码是:

#include <iostream>
#include <boost/dynamic_bitset.hpp>       
#include <vector>
#include <fstream>


using namespace::std;

struct point {
    float fpr;
    float tpr;
    point(float x, float y)
    {
        fpr = x;
        tpr = y;
    }
};

float** combine_crisp(boost::dynamic_bitset<unsigned char> label, boost::dynamic_bitset<unsigned char> r_1, boost::dynamic_bitset<unsigned char> r_2, vector<int> fun)
{
    int  k = 0;
    boost::dynamic_bitset<unsigned char> r_12;
    const int LENGTH =   (int) fun.size();
    float **FprTpr;
    FprTpr = new float*[LENGTH];

    int P = (int) label.count();
    int N = (int) (~label).count();
    boost::dynamic_bitset<unsigned char> notlabel(~label);
    for(vector<int>::iterator it = fun.begin(); it != fun.end(); ++it)
    {
        FprTpr[k] = new float[2];
        if (*it == 1)         //----------------> 'A AND B'
        {
            r_12 = r_1 & r_2;
        }
        else if(*it == 2)  //---------------> 'NOT A AND B'
        {
            r_12 = ~r_1 & r_2;
        }
        else if(*it == 3) //----------------> 'A AND NOT B'
        {
            r_12 = r_1 & ~r_2;
        }
        else if(*it == 4) //----------------> 'A NAND B'
        {
            r_12 = ~(r_1 & r_2);
        }
        else if(*it == 5) //----------------> 'A OR B'
        {
            r_12 = r_1 | r_2;
        }
        else if(*it == 6) //----------------> 'NOT A OR B'; 'A IMP B'
        {
            r_12 = ~r_1 | r_2;
        }
        else if(*it == 7) //----------------> 'A OR NOT B' ;'B IMP A'
        {
            r_12 = r_1 | ~r_2;
        }
        else if(*it == 8)  //----------------> 'A NOR B'
        {
            r_12 = ~(r_1 | r_2);
        }
        else if(*it == 9) //----------------> 'A XOR B'
        {
            r_12 = r_1 ^ r_2;
        }
        else if(*it == 10) //----------------> 'A EQV B'
        {
            r_12 = ~(r_1 ^ r_2);
        }
        FprTpr[k][0] = (r_12 & notlabel).count() / (float)N;
        FprTpr[k][1] = (r_12 & label).count() / (float)P;

        k++;
    }
    return FprTpr;
}

int main(int argc, char* argv[])
{               

    std::string inputFile;
    std::string outputFile;
    int  first_classifier  = 0;      

    for (int fo = 1; fo <= 5; fo++)
    {

        inputFile = "./vectors.txt";    

        outputFile += "./bccpoints.txt";

        std::ifstream infileFirst(inputFile);

        boost::dynamic_bitset<unsigned char> label;

        std::vector<boost::dynamic_bitset<unsigned char> > classifiers;

        std::string line;
        int numberOfClassifiers = -1;
        int lenOfClassifiers = -1;
        while (std::getline(infileFirst, line))
        {
            if (numberOfClassifiers == -1)
            {
                lenOfClassifiers = (int)std::string(line).length();
                label = boost::dynamic_bitset<unsigned char> (line);
            }
            else
            {
                classifiers.push_back(boost::dynamic_bitset<unsigned char> (line));
            }
            numberOfClassifiers++;
        }

        static const int arr[] = {1,2,3,4, 5,6,7,8,9,10};
        vector<int> fun (arr, arr + sizeof(arr) / sizeof(arr[0]) );
        static const int BOOLEANSIZE = fun.size();

        int NUMBER = numberOfClassifiers;

        float **rs_tmp;
        vector<point> current_points;

        for (int i = first_classifier; i < NUMBER; i++)
        {
            for (int j = 0; j < NUMBER; j++)
            {
                rs_tmp = combine_crisp(label, classifiers[i], classifiers[j], fun);

                for (int kk = 0; kk < BOOLEANSIZE; kk++) //creating row
                {
                    current_points.push_back( point(rs_tmp[kk][0], rs_tmp[kk][1] ) );
                    //                current_points.push_back ({rs_tmp[kk][0], rs_tmp[kk][1]});
                }
            }
        }
        delete[] rs_tmp;


        ofstream files;
        files.open (outputFile);
            files.write(reinterpret_cast<char*>(current_points.data()), current_points.size() * sizeof(point));



            std::vector<boost::dynamic_bitset<unsigned char> >().swap(classifiers);
            std::vector<point>().swap(current_points);
    }

}
#包括
#包括
#包括
#包括
使用namespace::std;
结构点{
浮动fpr;
浮动tpr;
点(浮动x、浮动y)
{
fpr=x;
tpr=y;
}
};
float**combine_crisp(boost::dynamic_位集标签,boost::dynamic_位集r_1,boost::dynamic_位集r_2,vector fun)
{
int k=0;
boost::动态位集r_12;
const int LENGTH=(int)fun.size();
浮动**FprTpr;
FprTpr=新浮点数*[长度];
int P=(int)label.count();
int N=(int)(~label).count();
boost::dynamic_位集notlabel(~label);
for(vector::iterator it=fun.begin();it!=fun.end();++it)
{
FprTpr[k]=新浮点数[2];
如果(*it==1)/------------->“A和B”
{
r_12=r_1和r_2;
}
如果(*it==2)/------------->“不是A和B”
{
r_12=~r_1&r_2;
}
如果(*it==3)/--------------------->“A而非B”,则为else
{
r_12=r_1和r_2;
}
如果(*it==4)/--------------------->“A和B”,则为else
{
r_12=~(r_1和r_2);
}
如果(*it==5)/--------------------->“A或B”,则为else
{
r_12=r_1 | r_2;
}
如果(*it==6)/------------->“不是A或B”;“A IMP B”
{
r_12=~r_1 | r_2;
}
如果(*it==7)/------------->“A或非B”;“B IMP A”
{
r_12=r_1 | ~r_2;
}
如果(*it==8)/----------------------->“A或B”
{
r_12=~(r_1 | r_2);
}
如果(*it==9)/----------------------->“A或B”
{
r_12=r_1^r_2;
}
如果(*it==10)/----------------------->“A等式B”
{
r_12=~(r_1^r_2);
}
FprTpr[k][0]=(r_12¬label).count()/(float)N;
FprTpr[k][1]=(r_12&label).count()/(float)P;
k++;
}
返回FprTpr;
}
int main(int argc,char*argv[])
{               
std::字符串输入文件;
std::字符串输出文件;
int first_分类器=0;

对于(int fo=1;fo请查找以下代码中的删除调用

    for (int i = first_classifier; i < NUMBER; i++)
    {
        for (int j = 0; j < NUMBER; j++)
        {
            rs_tmp = combine_crisp(label, classifiers[i], classifiers[j], fun);

            for (int kk = 0; kk < BOOLEANSIZE; kk++) //creating row
            {
                current_points.push_back( point(rs_tmp[kk][0], rs_tmp[kk][1] ) );
                //                current_points.push_back ({rs_tmp[kk][0], rs_tmp[kk][1]});
            }

            int size = fun.size();
            for(int i = 0; i < size; ++i)     // Iterate over each item in the array
            {
                delete[] rs_tmp[i]; // free the float array of size 2 you created in the other function
            }

            delete[] rs_tmp; // finally delete the float* array of size - fun.size()
        }
    } 
for(int i=first_分类器;i
请在下面的代码中查找删除呼叫

    for (int i = first_classifier; i < NUMBER; i++)
    {
        for (int j = 0; j < NUMBER; j++)
        {
            rs_tmp = combine_crisp(label, classifiers[i], classifiers[j], fun);

            for (int kk = 0; kk < BOOLEANSIZE; kk++) //creating row
            {
                current_points.push_back( point(rs_tmp[kk][0], rs_tmp[kk][1] ) );
                //                current_points.push_back ({rs_tmp[kk][0], rs_tmp[kk][1]});
            }

            int size = fun.size();
            for(int i = 0; i < size; ++i)     // Iterate over each item in the array
            {
                delete[] rs_tmp[i]; // free the float array of size 2 you created in the other function
            }

            delete[] rs_tmp; // finally delete the float* array of size - fun.size()
        }
    } 
for(int i=first_分类器;i
请在下面的代码中查找删除呼叫

    for (int i = first_classifier; i < NUMBER; i++)
    {
        for (int j = 0; j < NUMBER; j++)
        {
            rs_tmp = combine_crisp(label, classifiers[i], classifiers[j], fun);

            for (int kk = 0; kk < BOOLEANSIZE; kk++) //creating row
            {
                current_points.push_back( point(rs_tmp[kk][0], rs_tmp[kk][1] ) );
                //                current_points.push_back ({rs_tmp[kk][0], rs_tmp[kk][1]});
            }

            int size = fun.size();
            for(int i = 0; i < size; ++i)     // Iterate over each item in the array
            {
                delete[] rs_tmp[i]; // free the float array of size 2 you created in the other function
            }

            delete[] rs_tmp; // finally delete the float* array of size - fun.size()
        }
    } 
for(int i=first_分类器;i
请在下面的代码中查找删除呼叫

    for (int i = first_classifier; i < NUMBER; i++)
    {
        for (int j = 0; j < NUMBER; j++)
        {
            rs_tmp = combine_crisp(label, classifiers[i], classifiers[j], fun);

            for (int kk = 0; kk < BOOLEANSIZE; kk++) //creating row
            {
                current_points.push_back( point(rs_tmp[kk][0], rs_tmp[kk][1] ) );
                //                current_points.push_back ({rs_tmp[kk][0], rs_tmp[kk][1]});
            }

            int size = fun.size();
            for(int i = 0; i < size; ++i)     // Iterate over each item in the array
            {
                delete[] rs_tmp[i]; // free the float array of size 2 you created in the other function
            }

            delete[] rs_tmp; // finally delete the float* array of size - fun.size()
        }
    } 
for(int i=first_分类器;i