<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Create dynamically instances</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/00d97db419/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/00d97db419/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/00d97db419/</id><updated>2020-02-27T22:17:05.781000Z</updated><subtitle>Recent posts to Create dynamically instances</subtitle><entry><title>Create dynamically instances</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/00d97db419/?limit=25#29b4" rel="alternate"/><published>2020-02-27T22:17:05.781000Z</published><updated>2020-02-27T22:17:05.781000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com26beaaef6613e8929fbce361b059aa01eaf38e4f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; Bernhard Werner&lt;/p&gt;
&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;In Version 3 Codesys supports a new Operator (__NEW, __DELETE) for dynamic creation of function blocks.&lt;br/&gt;
You should use it carefully, because all the problems with leaks, duplicate delete or pointer to freed memory have to be considered.&lt;br/&gt;
In Version 2.3 you can allocate memory if your target supports the library SysLibMem. And once you have allocated the memory you can use it via pointer as any type you want.&lt;br/&gt;
Like for example:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;VAR&lt;/span&gt;
    &lt;span class="nv"&gt;pinst&lt;/span&gt; : &lt;span class="nv"&gt;POINTER&lt;/span&gt; &lt;span class="nv"&gt;TO&lt;/span&gt; &lt;span class="nv"&gt;FBTest&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="nv"&gt;bInit&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
   &lt;span class="nv"&gt;bInit&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;FALSE&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
   &lt;span class="nv"&gt;pinst&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;SysMemAlloc&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;SIZEOF&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;pinst&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="ss"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;;   (*allocation of bytes*)&lt;/span&gt;
   &lt;span class="nv"&gt;bDummy&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;INI&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;pinst&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;, &lt;span class="nv"&gt;TRUE&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;         (*initialisation of instance*)&lt;/span&gt;
&lt;span class="nv"&gt;END_IF&lt;/span&gt;
&lt;span class="nv"&gt;pinst&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;l&lt;/span&gt;, &lt;span class="nv"&gt;b&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;m&lt;/span&gt;, &lt;span class="nv"&gt;c&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;n&lt;/span&gt;, &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;l&lt;/span&gt;, &lt;span class="nv"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;m&lt;/span&gt;, &lt;span class="nv"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;n&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;So, in principle, its possible. One Problem is, that you have to take care that the memory is freed again, and that's a problem, because on the next download SysMemFree won't be called automatically.&lt;br/&gt;
An online change on FBTest by changing the Interface would lead to a crash.&lt;br/&gt;
I really can't recommend to use it.&lt;/p&gt;
&lt;p&gt;Bernhard&lt;/p&gt;
&lt;p&gt;Bernhard&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Create dynamically instances</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/00d97db419/?limit=25#e33e" rel="alternate"/><published>2020-02-27T22:17:04.249000Z</published><updated>2020-02-27T22:17:04.249000Z</updated><author><name>laythea</name><uri>https://forge.codesys.com/u/laythea/</uri></author><id>https://forge.codesys.comc00352a759c1a57aca79018527f74fe709015723</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I could be wrong here, but I haven't figured out how to dynamically allocate memory. I think we cant.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Create dynamically instances</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/00d97db419/?limit=25#1902" rel="alternate"/><published>2020-02-27T22:16:59.920000Z</published><updated>2020-02-27T22:16:59.920000Z</updated><author><name>Romuald</name><uri>https://forge.codesys.com/u/romuald/</uri></author><id>https://forge.codesys.com948b92fde55bacdde1546fb237427083ee86cdb5</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi all,&lt;/p&gt;
&lt;p&gt;Is it possible to create an instance dynamically as the 'new' keyword in other languages like C++ or JAVA ?&lt;/p&gt;
&lt;p&gt;Romuald.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>