简体   繁体   English

在本征中如何布置记忆?

[英]How is the memory layed out in Eigen?

I have written this little parser that reads in some numbers from text file. 我写了这个小解析器,它从文本文件中读取一些数字。

    data.resize(7,datapoints); //Eigen::Matrix<float,7,-1> & data
    dst = data.data();

    while( fgets(buf,255,fp) != 0 && i/7 < datapoints)
    {

        int n = sscanf(buf,"%f \t%f \t%f \t%f \t%f \t%f \t%f",dst+i++, dst+i++,dst+i++,dst+i++,dst+i++,dst+i++,dst+i++);
            i = i - 7 * (n<=0);
    }
    fclose(fp);
    return !(datapoints == i/7);

The thing is, when i do a std::cout on the data it flipped. 问题是,当我对翻转的数据执行std :: cout时。

Data in: 数据在:

0   4   0.35763609  0.64077979  0   0   1
0   4   0.36267641  0.68243247  1   0   2
0   4   0.37477320  0.72945964  2   1   3

data.col(3) is data.col(3)是

0.64077979  
0.68243247  
0.72945964 

and data.col(4) is 并且data.col(4)是

0.35763609  
0.36267641  
0.37477320 

I cant see the logic why it have flipped the data horizontal? 我看不到逻辑为什么将数据水平翻转?

To illustrate the problem: 为了说明问题:

#include <cstdio>

void f(int i, int j, int k)
{
  printf("i = %d\tj = %d\tk = %d\n", i, j, k);
}

int main()
{
  int i=0;
  f(i++, i++, i++);
}

Executing this, returns here (g++ 4.3.4 on Cygwin): 执行此操作,返回此处(Cygwin上的g ++ 4.3.4):

i = 2   j = 1   k = 0

The execution order of the i++ calls inside the function call is entirely implementation defined (ie arbitrary). 函数调用内部的i++调用的执行顺序完全由实现定义(即任意)。

Are you sure than? 你确定吗?

int i=0;
sscanf(buf,"%f \t%f \t%f \t%f \t%f \t%f \t%f",dst+i++, dst+i++,dst+i++,dst+i++,dst+i++,dst+i++,dst+i++);

is equal to: 等于:

sscanf(buf,"%f \t%f \t%f \t%f \t%f \t%f \t%f",dst+0,dst+1,dst+2,dst+3,dst+4,dst+5,dst+6 );

I think the variable list arg is geting evaluated back in this case, and as @Christian Rau comment in general is Undefined the order of evaluation. 我认为在这种情况下,变量列表arg正在重新评估,因为@Christian Rau的注释通常是未定义评估的顺序。 Oft it is not a good idea to realy on side -effect order. 要实现副作用顺序,通常不是一个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM