2016-05-03 13 views
0

2つのベクトルを連結するときに問題が発生します。2つのベクトルを連結するときのstd :: bad_alloc

std::vector<Transform3D> out; 
for(double theta = 0; theta <= 2*M_PI ; theta+=1) 
{ 
    for(double phi = 0; phi <= M_PI ; phi+=1) 
    { 
     double sphere_x = obj_x + r*cos(theta)*sin(phi); 
     double sphere_y = obj_y + r*sin(theta)*sin(phi); 
     double sphere_z = obj_z + + r*cos(phi); 
     Transform3D<> transformation_matrix = transform(obj_x,obj_y,obj_z,sphere_x,sphere_y,sphere_z); 

     if(0.01<(transformation_matrix.P()[0] - current_x) || 
      0.01<transformation_matrix.P()[1] - current_y || 
      0.01<transformation_matrix.P()[2] - current_z) 
     { 
      cout << "Interpolate: " << endl; 
      std::vector<Transform3D> transformation_i = invKin_LargeDisplacement(transformation_matrix); 

      out.insert(out.end(),transformation_i.begin(),transformation_i.end()); 
     } 
     else 
     { 
      cout << "OK" << endl; 
      out.push_back(transformation_matrix); 
     } 
     cout << out.size() << endl; 
     cout << sizeof(Transform3D<>) << endl; 
    } 
} 

out.insert(..)bad_allocを引き起こしているようだが、余分なデータが必要とされています。

Interpolate: 
6346700 
Interpolate: 
12052200 
Interpolate: 
16476100 
Interpolate: 
20127501 
Interpolate: 
26474201 
Interpolate: 
32239601 
Interpolate: 
36748301 
Interpolate: 
40416502 
Interpolate: 
46763202 
Interpolate: 
52659402 
Interpolate: 
57349102 
Interpolate: 
61053903 
Interpolate: 
67400603 
Interpolate: 
73377503 
Interpolate: 
terminate called after throwing an instance of 'std::bad_alloc' 
    what(): std::bad_alloc 
Aborted (core dumped) 

はまだにできることながら、私は、 bad_allocを避けることができますいくつかの方法があります:問題をデバッグしている間、私はループの実行中に、ベクトルの大きさを印刷し、次の出力を得た

補間?

+0

メモリが不足しています。メモリ使用量を調整できる場所を探す時間。 – StoryTeller

+0

私はスワップをまだ使用していません。 – Lamda

+1

7,300万のオブジェクトは、多くのメモリになります。 'sizeof(rw :: math :: Transform3D <>)とは何ですか? – NathanOliver

答えて

0

私たちはあなたの転換を仮定した場合山車の4×4アレイ(4バイト)とのPoDです:例外= 73377503

での配列の変換= 4 * 4 * 4 = 64バイト
サイズの

サイズ

64 * 73377503 = 4696160192バイト= 4.696160192ギガバイトこの大きさのベクトルで

私はあなたがメモリ不足を期待...あなたがあなたのマシンを持っているとあなたが本当のやるにはどうすればよいだけのメモリ

4.7Gbの変換データが必要ですか?

おそらくメモリ内のデータを圧縮したり、ファイルキャッシュに書き込んだりすることが考えられます。

関連する問題