你将如何使用二维来处理一维内存
How would you address one dimensional memory using two dimensions?
如何使用二维来寻址一维内存?(例如获得值Matrix::ValueAt(row, col)
,其中Matrix
将值存储为一维阵列(对于4x4矩阵为float m[16]
)。
class Matrix4x4
{
private float m[16];
float getValueAt(int row, int col)
{
// I want this function
}
}
使用m[row * 4 + col]
,或者相反。
让编译器弄清楚:
class Matrix4x4
{
private:
union
{
float m[16];
float m2[4][4];
};
public:
float getValueAt(int row, int col)
{
return m2[row][col];
}
float getValueAtLinear(int i)
{
return m[i];
}
}
一般情况下:
矩阵(i,j)=m[i*列+j]
相关文章:
- 将二维矢量传递给类
- 将值从二维数组输出到文本文件
- 我在二维向量中是否正确分配了内存
- 带结构的二维矢量:如何存储元素
- 在二维数组中查找最小值和最大值?
- 移动二维数组中的字符
- C++ 传递二维字符数组
- 如何正确填充在堆上分配的二维数组?
- 传递二维数组时出现问题
- 具有随机数的二维数组不会更改
- 如何在C++中获取二维数组中最少的一列数?
- 如何使用用户输入变量制作二维数组?
- C++ 中的二维整数数组,每行中的元素数量不均匀
- C++ 中动态二维数组的访问冲突
- 在二维向量或数组中可以存储的最大元素数是多少?
- 如何处理二维数组
- 你将如何使用二维来处理一维内存
- 在 Matlab 中调用C++函数,处理二维数组,指针指针
- 在opengl中处理三维或二维图形的点击
- 我如何使用条件结果来告诉程序要处理哪个二维数组?