check array elements if changed and update values for large arrays in a very fast way in c++

567 views Asked by At

I have the following code:

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;

An array of structs is initialized at the beginning and checked for changes. If changes occur the values in the array should be updated. The problem is that the current code is very slow, I know that changes occur every 100 miliseconds. for small arrays it works fine. Nevertheless, if the array is large( 3000 elements) the update time delay is over 3s. Is there a better way to compare and update the elements of the array?

the areEqual function looks like this: return fabs(a - b) < 0.000000000001;

and the saveValues() looks like this:

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); 

Thank you for any help! Greetings Ed

0

There are 0 answers