<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Operator _NEW für Speicherreservierung</title><link href="https://forge.codesys.com/forge/talk/Deutsch/thread/3235c06edd/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Deutsch/thread/3235c06edd/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Deutsch/thread/3235c06edd/</id><updated>2023-02-09T08:40:03.737000Z</updated><subtitle>Recent posts to Operator _NEW für Speicherreservierung</subtitle><entry><title>Operator _NEW für Speicherreservierung</title><link href="https://forge.codesys.com/forge/talk/Deutsch/thread/3235c06edd/?limit=25#c0cf" rel="alternate"/><published>2023-02-09T08:40:03.737000Z</published><updated>2023-02-09T08:40:03.737000Z</updated><author><name>narco22</name><uri>https://forge.codesys.com/u/narco22/</uri></author><id>https://forge.codesys.com3598c03ec42994df809a533e783e5c58bb9f2a77</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Danke für die Erläuterung, hat mir schon geholfen.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Operator _NEW für Speicherreservierung</title><link href="https://forge.codesys.com/forge/talk/Deutsch/thread/3235c06edd/?limit=25#2426" rel="alternate"/><published>2023-02-03T05:00:21.992000Z</published><updated>2023-02-03T05:00:21.992000Z</updated><author><name>nano</name><uri>https://forge.codesys.com/u/nano/</uri></author><id>https://forge.codesys.com78dec89a072e07a7d58817c4c549b720e02c074c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Was ich bei dir nicht Verstehe ist:&lt;br/&gt;
psPtrToString&lt;span&gt;[i]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Was machst du mit &lt;span&gt;[i]&lt;/span&gt;?&lt;br/&gt;
Willst du direkt auf die Chars zugreifen?&lt;/p&gt;
&lt;p&gt;Grundsätzlich liegt dein Problem jedoch in der Tatsache (zumindest auf basis der spärlichen Infos die wir haben), darin das du den Pointer nutzt, aber eigentlich willst du ne dereferenzierung um die Speicheradresse zu erhalten.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;VAR&lt;/span&gt;
    &lt;span class="nt"&gt;xInit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nd"&gt;BOOL&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;TRUE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;psPtrToString&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;POINTER&lt;/span&gt; &lt;span class="nt"&gt;TO&lt;/span&gt; &lt;span class="nt"&gt;STRING&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;sText&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nd"&gt;STRING&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;sOutText&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nd"&gt;STRING&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;

&lt;span class="nt"&gt;IF&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;xInit&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nt"&gt;THEN&lt;/span&gt;
    &lt;span class="nt"&gt;psPtrToString&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;__NEW&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;STRING&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;8&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="nt"&gt;xInit&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;FALSE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_IF&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;psPtrToString&lt;/span&gt;&lt;span class="o"&gt;^:=&lt;/span&gt; &lt;span class="nt"&gt;sText&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;sOutText&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;psPtrToString&lt;/span&gt;&lt;span class="o"&gt;^;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Hier wird der Speicher allcoiert, und die Speicheradresse im Pointer gespeichert.&lt;/p&gt;
&lt;p&gt;Später wird der Dereferenzierte Pointer (siehe ^ nach Pointername) mit einem String beschrieben.&lt;br/&gt;
in der nächsten Zeile wird (völlig sinnfrei in diesem Beispiel) der im neu allocierten Speicher hinterlegte WErte ebenfalls durch dereferenzierten Pointer der NEW-Anweisung in einen anderen Speicher zurückgegeben.&lt;/p&gt;
&lt;p&gt;Als grundlagen Beispiel sollte dies eigentlich reichen.&lt;/p&gt;
&lt;p&gt;Auch sei in diesem Zuge auf:&lt;br/&gt;
&lt;a href="https://content.helpme-codesys.com/de/CODESYS%20Development%20System/_cds_operator_new.html" rel="nofollow"&gt;https://content.helpme-codesys.com/de/CODESYS%20Development%20System/_cds_operator_new.html&lt;/a&gt;&lt;br/&gt;
Verwiesen&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Operator _NEW für Speicherreservierung</title><link href="https://forge.codesys.com/forge/talk/Deutsch/thread/3235c06edd/?limit=25#9a72" rel="alternate"/><published>2023-02-02T12:38:20.605000Z</published><updated>2023-02-02T12:38:20.605000Z</updated><author><name>narco22</name><uri>https://forge.codesys.com/u/narco22/</uri></author><id>https://forge.codesys.com780dede74827727b67ffd6a888af6fff466aba9b</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hallo Leute,&lt;/p&gt;
&lt;p&gt;ich hätte mal eine Frage zur Verwendung des Operators NEW für die Speicherreservierung. Mit dem Operator möchte ich z.B. acht String-Speicherstellen reservieren. Die Syntax sieht dann folgendermaßen aus:&lt;/p&gt;
&lt;p&gt;psPtrToString:= NEW(STRING, 8).&lt;/p&gt;
&lt;p&gt;Der Operator erzeugt ja dann zur Laufzeit ein Array des Typs STRING. Auf die einzelnen Array-Elemente möchte ich zugreifen und Werte hineinschreiben. Wie greift man darauf zu?&lt;/p&gt;
&lt;p&gt;psPtrToString&lt;span&gt;[i]&lt;/span&gt;:= sText scheint nicht zu funktionieren.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>