Suppose i have 2 arrays,
array1 : array [0..999] of real;
array2 : array [0..999] of real;
Components of array2 need to be mapped into array1.
For this, in text file i have made mapping data as below.
0=50 (means array1:=array2)
by reading the text file, i have stored index numbers of array2 to another array.
FOR i:=0 to 999 DO
My question is, is it possible to do this kind of mapping without using loop? (by using pointer or reference??)
the problem is the number of data could be 100,000 or more and for loop might cause a problem such as delay, CPU usage...
Maybe there are some "memory level" ways of mapping which is very fast. Do you have any idea?
How about using memcpy
Its been a while since I've tested memcpy against a loop but if memory serves me correctly using memcpy wasn't any faster which lead me to believe it was just doing the loop for me. Anyone know if this is true?
Just checked it with Twincat3, memcpy is 3 times faster then a loop. I checked this by copying 1000000 real from one array to another.
I don't understand why loop is not required if memcpy is used.
memcpy just copies one block of memory to another which can be used to copy a whole array to another one.
however in my case, it has to map values of array components to another as below.
Could you please show me an example of code using memcpy for data mapping?
@audi0615, from library SysMem, SysMemCpy is relatively straight forward. You have three inputs: pDest (destination array), pSrc (source array), and udiCount (total bytes). You will need to use ADR to get reference pointer.
SysMemCpy(pDest:=ADR(array2), pSrc:=ADR(array1), udiCount:=4000); // 4*1000
Log in to post a comment.