我有以下代码:
const int size=9;
mtype array[size];
array[0]...
array[0].Value=me->getRootInstance()->A();
array[0]...
...
array[3000]...
array[3000].Value=me->getRootInstance()->A3000();
array[3000]...
while(Logging::getLogging()){
if(!areEqual(array[0].Value,me->getRootInstance()->A())){array[0].Value=me->getRootInstance()->A(); saveValue(array[0]);}
...
if(!areEqual(array[3000].Value,me->getRootInstance()->A3000())){array[3000].Value=me->getRootInstance()->A3000(); saveValue(array[3000]);}
}
return 0;
结构数组在开始时被初始化并检查更改。如果发生更改,则应更新数组中的值。问题是当前代码非常慢,我知道每 100 毫秒就会发生一次更改。对于小型阵列,它工作正常。然而,如果数组很大(3000 个元素),更新时间延迟超过 3 秒。有没有更好的方法来比较和更新数组的元素?
areEqual 函数如下所示:return fabs(a - b) < 0.000000000001;
saveValues() 看起来像这样:
OMGuard _omGuard(r_omGuard);
int tc = clock()-Logging::getStarttime(); //clicks
double seconds = ((double)tc)/CLOCKS_PER_SEC;
mtype *newstruct = new mtype();
newstruct->Calltime = seconds;
newstruct->Name = melem.Name;
newstruct->Value = melem.Value;
newstruct->GUID = melem.GUID;
newstruct->ReqName = melem.ReqName;
newstruct->ReqGUID = melem.ReqGUID;
monitoredlist.add(newstruct);
感谢您的任何帮助!问候编辑