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?
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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
@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.
Hi.
Suppose i have 2 arrays,
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[0]:=array2[50])
1=90
2=100
...
by reading the text file, i have stored index numbers of array2 to another array.
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?
Related
Talk.ru: 1
Talk.ru: 2
How about using memcpy
https://help.codesys.com/webapp/m0ZSKwt2k9t9COsbw6YPd_jvtjs%2FMemCpy;product=MemoryUtils;version=3.5.9.0
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.
Last edit: wollvieh 2020-06-15
Thanks Gentlemen.
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?
Related
Talk.ru: 1
Talk.ru: 2
@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