<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to data mapping array without loop</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dcdb227d37/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dcdb227d37/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/dcdb227d37/</id><updated>2020-07-25T04:57:56.074000Z</updated><subtitle>Recent posts to data mapping array without loop</subtitle><entry><title>data mapping array without loop</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dcdb227d37/?limit=25#ba43" rel="alternate"/><published>2020-07-25T04:57:56.074000Z</published><updated>2020-07-25T04:57:56.074000Z</updated><author><name>nothinrandom</name><uri>https://forge.codesys.com/u/nothinrandom/</uri></author><id>https://forge.codesys.com533a4a8d8e8c624399d429959027f90d28c161ad</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;a class="user-mention" href="/u/audi0615/"&gt;@audi0615&lt;/a&gt;, 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.&lt;/p&gt;
&lt;p&gt;SysMemCpy(pDest:=ADR(array2), pSrc:=ADR(array1), udiCount:=4000); // 4*1000&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>data mapping array without loop</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dcdb227d37/?limit=25#820d" rel="alternate"/><published>2020-06-15T23:46:09.460000Z</published><updated>2020-06-15T23:46:09.460000Z</updated><author><name>audi0615</name><uri>https://forge.codesys.com/u/audi0615/</uri></author><id>https://forge.codesys.com80918ca063487459a439c583aca8f86ce889101c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thanks Gentlemen.&lt;/p&gt;
&lt;p&gt;I don't understand why loop is not required if memcpy is used.&lt;br/&gt;
memcpy just copies one block of memory to another which can be used to copy a whole array to another one.&lt;br/&gt;
however in my case, it has to map values of array components to another as below.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;array1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;array2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;array1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;array2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;array1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;array2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;....&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Could you please show me an example of code using memcpy for data mapping?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>data mapping array without loop</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dcdb227d37/?limit=25#2e7c" rel="alternate"/><published>2020-06-15T20:10:28.947000Z</published><updated>2020-06-15T20:10:28.947000Z</updated><author><name>wollvieh</name><uri>https://forge.codesys.com/u/wollvieh/</uri></author><id>https://forge.codesys.com2a1f18acc166f44b4c73135f5fcc869d9ada831e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Just checked it with Twincat3, sysmcpy is 3 times faster then a loop. I checked this by copying 1000000 real from one array to another. &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>data mapping array without loop</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dcdb227d37/?limit=25#6e0c" rel="alternate"/><published>2020-06-15T16:36:23.032000Z</published><updated>2020-06-15T16:36:23.032000Z</updated><author><name>Comingback4u</name><uri>https://forge.codesys.com/u/comingback4u/</uri></author><id>https://forge.codesys.com3c48c90166cf26c799f35829e9a6589a9f0b1207</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;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?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>data mapping array without loop</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dcdb227d37/?limit=25#7dad" rel="alternate"/><published>2020-06-13T12:16:05.149000Z</published><updated>2020-06-13T12:16:05.149000Z</updated><author><name>wollvieh</name><uri>https://forge.codesys.com/u/wollvieh/</uri></author><id>https://forge.codesys.comb555fd920f003cbad243cabb24346c1f8adb366b</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;How about using memcpy&lt;/p&gt;
&lt;p&gt;&lt;a href="https://help.codesys.com/webapp/m0ZSKwt2k9t9COsbw6YPd_jvtjs%2FMemCpy;product=MemoryUtils;version=3.5.9.0" rel="nofollow"&gt;https://help.codesys.com/webapp/m0ZSKwt2k9t9COsbw6YPd_jvtjs%2FMemCpy;product=MemoryUtils;version=3.5.9.0&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>data mapping array without loop</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/dcdb227d37/?limit=25#7823" rel="alternate"/><published>2020-06-13T02:07:06.889000Z</published><updated>2020-06-13T02:07:06.889000Z</updated><author><name>audi0615</name><uri>https://forge.codesys.com/u/audi0615/</uri></author><id>https://forge.codesys.com9f9abdc5d4ab1a1f8aea5cf88b79df1026bee618</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;Suppose i have 2 arrays,&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;array1&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;999&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;real&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;array2&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;999&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;real&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Components of array2 need to be mapped into array1.&lt;br/&gt;
For this, in text file i have made mapping data as below.&lt;/p&gt;
&lt;p&gt;0=50 (means array1&lt;span&gt;[0]&lt;/span&gt;:=array2&lt;span&gt;[50]&lt;/span&gt;)&lt;br/&gt;
1=90&lt;br/&gt;
2=100&lt;br/&gt;
...&lt;/p&gt;
&lt;p&gt;by reading the text file, i have stored index numbers of array2 to another array.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;arIndex&lt;/span&gt;[&lt;span class="mi"&gt;0&lt;/span&gt;]:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;arIndex&lt;/span&gt;[&lt;span class="mi"&gt;1&lt;/span&gt;]:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;900&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;arIndex&lt;/span&gt;[&lt;span class="mi"&gt;2&lt;/span&gt;]:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
......

&lt;span class="k"&gt;FOR&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="mi"&gt;999&lt;/span&gt; &lt;span class="k"&gt;DO&lt;/span&gt;

    &lt;span class="nv"&gt;indexnum&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;arIndex&lt;/span&gt;[&lt;span class="nv"&gt;i&lt;/span&gt;]&lt;span class="c1"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;array1&lt;/span&gt;[&lt;span class="nv"&gt;i&lt;/span&gt;]:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;array2&lt;/span&gt;[&lt;span class="nv"&gt;indexnum&lt;/span&gt;]&lt;span class="c1"&gt;; //mapping&lt;/span&gt;

&lt;span class="nv"&gt;END_FOR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;My question is, is it possible to do this kind of mapping without using loop? (by using pointer or reference??)&lt;br/&gt;
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...&lt;br/&gt;
Maybe there are some "memory level" ways of mapping which is very fast. Do you have any idea?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>