This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Unaligned array

Tags: None
(comma "," separated)
Scolohofo
Registered Member
Posts
8
Karma
0
OS

Unaligned array

Tue Oct 25, 2011 7:06 am
Hi!
This is a part of my code:
Code: Select all
#define _USE_MATH_DEFINES

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <Eigen/Geometry>
#include <Eigen/Dense>
#include <Eigen/Core>
#include <iostream>
#include <sys/timeb.h>
#include <fstream>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <utility>

using namespace Eigen;
using namespace std;

struct Point3D;
struct Triangle;
struct Rod;

#pragma region STUCTURES
struct Point3D
{
   size_t number;
   Vector3d PointVector;
   Vector3d PointVectorInRadarBasis;
   vector<Triangle*> triangles;
   vector<Rod*> rods;
   Matrix2d MatrixT;
   bool visibility;
};

struct Triangle
{
   size_t number;
   vector<Point3D*> points;
   Point3D midpoint;
   size_t Material;
   Vector3d normal;
   Vector3d Vec1;
   Vector3d Vec2;
   bool visibility;
   double area;
   double AngleWithRadar;
};

struct Rod
{
   size_t number;
   vector<Point3D*> points;
   size_t Material;
   bool visibility;
};

struct RadarStation
{
   double teta;
   double fi;
   Vector3d Ray;
   Matrix3d Basis;
};
#pragma endregion STUCTURES

#pragma region LOAD_UPLOAD

double NumbParser(string ExNumb)
{
   int pos=ExNumb.find_last_of('-');
   if(pos-1>=0)
   {
      if(ExNumb[pos-1]!=' ')
      return atof(ExNumb.substr(0,pos).c_str())*pow(10,atof(ExNumb.substr(pos,ExNumb.size()-1).c_str()));
   }
   pos=ExNumb.find_last_of('+');
   if(pos-1>=0)
      //ExNumb.find_last_of('+')&&ExNumb.find_last_of('+')!=-1&&ExNumb.find_last_of('+')!=ExNumb.find_first_of('+'))
   {
      if(ExNumb[pos-1]!=' ')
      return atof(ExNumb.substr(0,pos).c_str())*pow(10,atof(ExNumb.substr(pos,ExNumb.size()-1).c_str()));
   }
   return atof(ExNumb.c_str());
}



bool LoadFile(string Path,map<size_t,Point3D,less<size_t>>//load data from the text file

&points,map<size_t,Triangle,less<size_t>> &triangles,map<size_t,Rod,less<size_t>> &rods)
{
   char ctemp[100];
   string stemp;
   Point3D ptemp;
   Triangle ttemp;
   Rod rtemp;
   double FullArea=0;
   ifstream ifile(Path.c_str(),ios::in);
   if (!ifile)
   {
      cout<<"Не могу открыть входной файл!\n";
      system("pause");
      return false;
   }
   else
   {
      cout<<"Входной файл открыт успешно!\n";
   }
   
   while(!ifile.eof())
   {
      ifile.getline(ctemp,100);
      stemp=ctemp;
      if (stemp.find_first_of("$*"))
      {
         if (stemp.substr(0,4)=="GRID")
         {
            ptemp.rods.resize(0);
            ptemp.triangles.resize(0);
            try
            {
               ptemp.number=atoi(stemp.substr(8,8).c_str());
               ptemp.PointVector.resize(3);
               ptemp.PointVector(0)=NumbParser(stemp.substr(24,8));
               ptemp.PointVector(1)=NumbParser(stemp.substr(32,8));
               ptemp.PointVector(2)=NumbParser(stemp.substr(40,8));
               ptemp.visibility=false;
      
points.insert(pair<int,Point3D>(ptemp.number,ptemp));//in this place my program crashed and compiler reported, that it's a problem with unaligned array
...}


I read abt that problem in tutorial, but... i don't understand:(
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Unaligned array

Tue Oct 25, 2011 7:29 am
Point3D stores a Matrix2d which must be aligned to exploit SSE. Consequently, as said in the tutorial, this class must have overloaded operator new (we have a macro for that), and any STL container storing Point3D objects should use our aligned_allocator. Consequently, the same apply to all classes storing a Point3D.

If you don't want such trouble, use a Matrix<double,2,2,Eigen::DontAlign> instead of Matrix2d for the member of Point3D.
Scolohofo
Registered Member
Posts
8
Karma
0
OS

Re: Unaligned array

Tue Oct 25, 2011 7:39 am
thanx, it's working well ;D


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]