本文介绍了在3D结构中快速设置字节变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个3d结构,其中包含Byte变量cCtrlVal.
我想在运行时将其尽快设置为255.
有5760个cCtrlVal实例.
目前,我正在遍历具有3个嵌套的for循环的矩阵.
有没有更好的方法来快速设置此变量?
提前谢谢.
:罗恩
Hi,
I have a 3d structure that contains a Byte variable cCtrlVal.
I would like to set this at runtime to 255 as fast as possible.
There are 5760 instances of cCtrlVal.
Currently I am looping through the matrix with 3 nested for loops.
This there a better quicker way to quick set this var?
Thanks in advance.
:Ron
struct typControlMatrix
{
BOOL bEnabled;
BOOL bChanged;
BOOL LastChange;
BOOL AdjStripNo;
BYTE cCtrlVal;
enum enControlType eCtrlType;
DWORD lCtrlNo;
char sStripDesc[MAX_SCRIBBLE_STRIP_DESC];
CString sCtrlVal;
BOOL bDescChanged;
int TrackPage;
int CompRatioIndex ;
DWORD lStripNo;
int lParamNo;
} m_tControlMatrix[128][5][9];
推荐答案
register int i, j, k;
LARGE_INTEGER t[4];
QueryPerformanceCounter(&t[0]);
//-> 3 loops
for (i=0; i<128; i++)
{
for (j=0; j<5; j++)
{
for (k=0; k<9; k++)
m_tControlMatrix[i][j][k].cCtrlVal = 255;
}
}
//<-
QueryPerformanceCounter(&t[1]);
QueryPerformanceCounter(&t[2]);
//-> flat pointers
register BYTE * p = &m_tControlMatrix[0][0][0].cCtrlVal;
register BYTE * q = p + 5760 * sizeof(typControlMatrix);
while (p < q)
{
*p = 255;
p += sizeof(typControlMatrix);
}
//<-
QueryPerformanceCounter(&t[3]);
CString s;
s.Format("3 loops: %I64d flat pointers: %I64d speed ratio %g ", (t[1].QuadPart-t[0].QuadPart), (t[3].QuadPart-t[2].QuadPart), ((double)(t[1].QuadPart-t[0].QuadPart))/(t[3].QuadPart-t[2].QuadPart));
MessageBox(s, "Test");
输出:
The output:
3 loops: 195327 flat pointers: 67743 speed ratio 2.88335
这篇关于在3D结构中快速设置字节变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!