0

有我的 Integrator_Cauchy 课程:

template <typename T_out,typename T_contour ,typename T_in> class C_Integrator_Cauchy: public C_Integrator{
protected:      
T_out (C_Integrator_Cauchy::*Integrator_ref)(T_contour * Contour,T_in * Point);

C_Integrator_Cauchy(int _NumPoints, double _LimDown, double _LimUp, int _NumAps, Integrator_ID id):C_Integrator(_NumPoints, _LimDown, _LimUp, _NumAps, id){}

public:
static C_Integrator_Cauchy * createIntegrator(int _NumPoints, double _LimDown, double _LimUp, int _NumAps, Integrator_ID id ){
    C_Integrator_Cauchy * p = 0; 
    switch (id)
    {
        case qcauchyleg_lin_ID:
            p = new C_Integrator_Cauchy(_NumPoints, _LimDown, _LimUp, _NumAps, id); 
            p->Integrator_ref=&C_Integrator_Cauchy::qcauchyleg_lin;
            p->setNodes(id);
            break;       
        default:
        cout << "Integrator_ID Error" << endl;
            assert( false);
    }
    return p;
}

T_out getResult(T_contour * Contour,T_in * Point){
    return (this->*Integrator_ref)(Contour,Point);
}

T_out qcauchyleg_lin(T_contour * Contour,T_in * Point)
{
    T_out result(NumAps);
    T_out F(NumAps),resF(NumAps),sumF(NumAps);
    T_in N,temp,sumN,resN;
    T_in z_i,dz_i,coordin;
    for (int i = 0; i < NumAps ; i++){sumF[i] = T_in(0.0,0.0);}
    sumN = T_in(0.0,0.0);

    for (int j=1;j<=NumPoints;j++) 
    {
        temp = w[j];
        z_i=(*Contour)[0][j-1];
        dz_i=(*Contour)[1][j-1];
        coordin=(*Point);
        for (int i = 0; i < NumAps ; i++){F[i]=conj(z_i-coordin)/norm(z_i-coordin)*dz_i*(*Contour)[i+2][j-1];}
        N=conj(z_i-coordin)/norm(z_i-coordin)*dz_i;
        for (int i = 0; i < NumAps ; i++){sumF[i] += temp*F[i];}
        sumN += temp*N;
    }   
    for (int i = 0; i < NumAps ; i++){  result[i]=(sumF[i]/sumN); }
    return result;
} };

还有最简单的 main.cpp

typedef complex<double> dcx;

typedef vector<vector<vector<double> > > dArray3D; 
typedef vector<vector<double> > dArray2D; 
typedef vector<double> dArray1D; 

typedef vector<vector<vector<dcx> > > dcxArray3D;
typedef vector<vector<dcx> > dcxArray2D;
typedef vector<dcx> dcxArray1D;

int main(int __argc,char *__argv[]){
    C_Integrator_Cauchy<dcxArray1D,dcxArray2D,dcx> * integ_cauchy=C_Integrator_Cauchy<dcxArray1D,dcxArray2D,dcx>::createIntegrator(2000, 0.0, 6.2831, 1, qcauchyleg_lin_ID);

    cout << "Start allocate something" << endl;
    dcxArray2D temp;
    temp.resize(1,dcxArray1D());
    for (int i = 0; i < 8000; i++){
        temp[0].push_back(1.0);
        cout << i << endl;
    }
    cin.get();

 return 0;
}

问题是 - 在 main.cpp 中创建 Integrator_Cauchy 后,不可能分配大向量(比如 i > 4000)。它抛出:

*** glibc detected *** ./main_test: free(): invalid next size (normal): 0x0a01acc8 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0xb74f3ee2]
/usr/lib/i386-linux-gnu/libstdc++.so.6(_ZdlPv+0x1f)[0xb76d6adf]
./main_test[0x804eb95]
./main_test[0x804d337]
./main_test[0x804d4ee]
./main_test[0x804c278]
./main_test[0x8051e4a]
./main_test[0x80515e0]
./main_test[0x804ffe7]
./main_test[0x804e710]
./main_test[0x804cf27]
./main_test[0x80498d3]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb74974d3]
./main_test[0x8049141]

尽管我在 RAM 中有足够多的内存空间,而且 Integrator_Cauchy 本身并不占用大量内存。

我正在 Ubuntu 12.10 上编译;g++ 4.7.2;

有任何想法吗?

4

0 回答 0