<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: methods deviceName() and plotDeviceList(), memory leak? in ObjectARX Forum</title>
    <link>https://forums.autodesk.com/t5/objectarx-forum/methods-devicename-and-plotdevicelist-memory-leak/m-p/6561154#M9616</link>
    <description>&lt;P&gt;Thanks a lot to tbrammer for your complementation and correction! Yes, my guess was wrong, when ObjectARX returning *const* string, the returned string (or in other words more accurately, the string pointed by the retuned pointer) is not pre-allocated in advance and can not be assumed to be there always in memory! So,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;1. For the returned *&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;non-const&lt;/STRONG&gt;&lt;/FONT&gt;* string, remember to call acutDelString() to free it after using it.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;2. For the returned *&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;const&lt;/STRONG&gt;&lt;/FONT&gt;* string, copy it to your own string variable as soon as getting it.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Sep 2016 10:31:41 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-09-14T10:31:41Z</dc:date>
    <item>
      <title>methods deviceName() and plotDeviceList(), memory leak?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/methods-devicename-and-plotdevicelist-memory-leak/m-p/6532834#M9612</link>
      <description>&lt;P&gt;In objectARX program, to list and select AutoCAD plot device, there are two ways I found:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Returns the device name or PC3 file name&lt;BR /&gt;class AcPlPlotConfigInfo's deviceName() method,&lt;BR /&gt;ACPL_PORT const &lt;FONT color="#0000FF"&gt;ACHAR *&lt;/FONT&gt; deviceName() const;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Returns an array of all available plot devices found on the system.&lt;BR /&gt;class AcDbPlotSettingsValidator's plotDeviceList() method.&lt;BR /&gt;virtual Acad::ErrorStatus plotDeviceList(AcArray&amp;lt;const &lt;FONT color="#0000FF"&gt;ACHAR *&lt;/FONT&gt;&amp;gt; &amp;amp; deviceList) = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the strings returned by them can't be freed with acutDelString(), does that mean &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;memory leak&lt;/FONT&gt;&lt;/STRONG&gt;?&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2016 02:44:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/methods-devicename-and-plotdevicelist-memory-leak/m-p/6532834#M9612</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-31T02:44:45Z</dc:date>
    </item>
    <item>
      <title>Re : methods deviceName() and plotDeviceList(), memory leak?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/methods-devicename-and-plotdevicelist-memory-leak/m-p/6533229#M9613</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;When methods returns &lt;STRONG&gt;const ACHAR*&lt;/STRONG&gt; values, it means that the values are not new copies of existing strings but the strings themselves.&lt;/P&gt;&lt;P&gt;This is explicitly specified by the &lt;STRONG&gt;const&lt;/STRONG&gt; keyword.&lt;/P&gt;&lt;P&gt;In that case you shouldn't try to free them if you don't want AutoCAD to crash...&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2016 09:11:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/methods-devicename-and-plotdevicelist-memory-leak/m-p/6533229#M9613</guid>
      <dc:creator>thierry_prince</dc:creator>
      <dc:date>2016-08-31T09:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: methods deviceName() and plotDeviceList(), memory leak?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/methods-devicename-and-plotdevicelist-memory-leak/m-p/6538732#M9614</link>
      <description>&lt;P&gt;Thanks so much to thierry.prince! Your reply reminds me of a puzzle always in my mind when reading objectARX documents.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The question is: When returning string, why some methods/functions return *&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;const&lt;/FONT&gt;&lt;/STRONG&gt;* string pointer, and the others return *&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;non-const&lt;/FONT&gt;&lt;/STRONG&gt;* string pointer?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I realize now that there are two kind of strings to return:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. For returning non-volatile, system-wide string, AutoCAD/objectARX allocates in advance this kind of limited number of fixed strings in memory, they always stay in memory, when returning, just gives the pointer to caller, there is no need for the caller to free the "returned" string. If the caller use acutDelString() to force "free" the returned string, AutoCAD will crash.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. For returning Trivial and volatile string, objectARX lets the method/function allocate the string with malloc() (or something like) in heap memory, and makes the caller repsonsible for freeing the retured string in heap memory with free() (or something like).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for my poor English &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2016 10:27:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/methods-devicename-and-plotdevicelist-memory-leak/m-p/6538732#M9614</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-09-02T10:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: methods deviceName() and plotDeviceList(), memory leak?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/methods-devicename-and-plotdevicelist-memory-leak/m-p/6540704#M9615</link>
      <description>&lt;P&gt;The ARX docs recommend not to store returned&amp;nbsp; &lt;FONT face="courier new,courier"&gt;const TCHAR *&lt;/FONT&gt;&amp;nbsp; pointers "for later use". Instead you should construct a &lt;FONT face="courier new,courier"&gt;CString&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;AcString&lt;/FONT&gt; object with them immediately because AutoCAD might release the pointers at some point.&lt;/P&gt;
&lt;P&gt;For example &lt;FONT face="courier new,courier"&gt;Acad::ErrorStatus AcDbSymbolTableRecord::getName(ACHAR*&amp;amp; pName) const;&lt;/FONT&gt; will return a layer name or a block name in &lt;FONT face="courier new,courier"&gt;pName&lt;/FONT&gt;. If the layer name changes the &lt;FONT face="courier new,courier"&gt;pName &lt;/FONT&gt;pointer will become invalid.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2016 10:33:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/methods-devicename-and-plotdevicelist-memory-leak/m-p/6540704#M9615</guid>
      <dc:creator>tbrammer</dc:creator>
      <dc:date>2016-09-03T10:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: methods deviceName() and plotDeviceList(), memory leak?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/methods-devicename-and-plotdevicelist-memory-leak/m-p/6561154#M9616</link>
      <description>&lt;P&gt;Thanks a lot to tbrammer for your complementation and correction! Yes, my guess was wrong, when ObjectARX returning *const* string, the returned string (or in other words more accurately, the string pointed by the retuned pointer) is not pre-allocated in advance and can not be assumed to be there always in memory! So,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;1. For the returned *&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;non-const&lt;/STRONG&gt;&lt;/FONT&gt;* string, remember to call acutDelString() to free it after using it.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;2. For the returned *&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;const&lt;/STRONG&gt;&lt;/FONT&gt;* string, copy it to your own string variable as soon as getting it.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 10:31:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/methods-devicename-and-plotdevicelist-memory-leak/m-p/6561154#M9616</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-09-14T10:31:41Z</dc:date>
    </item>
  </channel>
</rss>

