<?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: IMPORTANT! delete[] operator doesn't work in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249860#M5464</link>
    <description>I might not be seeing it ... but where did you do a 'new' to allocate the building_data object instantiation?</description>
    <pubDate>Sun, 01 Mar 2015 19:35:24 GMT</pubDate>
    <dc:creator>Karl Ottenstein</dc:creator>
    <dc:date>2015-03-01T19:35:24Z</dc:date>
    <item>
      <title>[SOLVED] IMPORTANT! delete[] operator doesn't work</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249859#M5463</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;Hi&lt;BR /&gt;&lt;BR /&gt;Why AC crashs when I call delete[] operator&lt;BR /&gt;My code separately works correctly&lt;BR /&gt;&lt;BR /&gt;Please give me an advise.&lt;BR /&gt;&lt;BR /&gt;Here is my add-on code&lt;BR /&gt;
&lt;PRE&gt;typedef void(*get_building_info) (const char *user_id, const char * token, Building *buildings[]);

	LPCWSTR dllName = helper::developer::getDllPath();
	HINSTANCE dynamicLib = LoadLibraryW(dllName);

	
	if (dynamicLib)
	{
		Building * building_data;
		get_building_info getdata = (get_building_info)GetProcAddress(dynamicLib, "get_building_info");
		getdata(this-&amp;gt;userId, this-&amp;gt;accessToken, &amp;amp;building_data);

		if (!building_data-&amp;gt;is_empty)
		{
			//Filling the building combobox
			m_comboBuilding.DeleteItem (DG::PopUp::AllItems);
			for (int c = 0; c &amp;lt; (int)building_data-&amp;gt;size; c++)
			{
				m_comboBuilding.AppendItem ();
				m_comboBuilding.SetItemText (DG::PopUp::BottomItem, GS::UniString::Printf("%s", building_data.name));
				m_comboBuilding.SetItemValue (DG::PopUp::BottomItem, (int)building_data.id);
			}
			delete[] building_data;
		}
	}&lt;/PRE&gt;
And here is the dll code&lt;BR /&gt;
&lt;PRE&gt;__declspec(dllexport) void get_building_info(const char * user_id, const char * token, Building *building_data[])
	{
		get_buildings_cpprest(user_id, token, *building_data).wait();

		if (!building_id.empty())
		{
			Building *b = new Building[building_id.size()];

			b-&amp;gt;is_empty = false;
			b-&amp;gt;size = building_id.size();

			for (int i = 0; i &amp;lt; building_id.size(); i++)
			{
				b&lt;I&gt;.id = const_cast&amp;lt;char*&amp;gt;(building_id&lt;I&gt;.c_str());
				b&lt;I&gt;.name = const_cast&amp;lt;char*&amp;gt;(building_name&lt;I&gt;.c_str());
			}
			*building_data = b;
		}
		else {
			
		}
  	}&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Aug 2023 11:37:02 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249859#M5463</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-01T11:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORTANT! delete[] operator doesn't work</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249860#M5464</link>
      <description>I might not be seeing it ... but where did you do a 'new' to allocate the building_data object instantiation?</description>
      <pubDate>Sun, 01 Mar 2015 19:35:24 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249860#M5464</guid>
      <dc:creator>Karl Ottenstein</dc:creator>
      <dc:date>2015-03-01T19:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORTANT! delete[] operator doesn't work</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249861#M5465</link>
      <description>I think global new and delete overriden by API.&lt;BR /&gt;
May be ::delete[] building_data will work;&lt;BR /&gt;
&lt;BR /&gt;
But actually it is poor DLL design. &lt;BR /&gt;
You need do and export function from DLL like &lt;BR /&gt;
release_building_info(Building *building_data[])&lt;BR /&gt;
and free the memory.</description>
      <pubDate>Mon, 02 Mar 2015 08:12:15 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249861#M5465</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2015-03-02T08:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORTANT! delete[] operator doesn't work</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249862#M5466</link>
      <description>&lt;BLOCKQUOTE&gt;Karl wrote:&lt;BR /&gt;I might not be seeing it ... but where did you do a 'new' to allocate the building_data object instantiation?&lt;/BLOCKQUOTE&gt;

I allocate with new operator in my dll code because I have to determine the size of building structure before filling it&lt;BR /&gt;

&lt;PRE&gt;_declspec(dllexport) void get_building_info(const char * user_id, const char * token, Building *building_data[]) 
   { 
      get_buildings_cpprest(user_id, token, *building_data).wait(); 

      if (!building_id.empty()) 
      { 
         Building *b = new Building[building_id.size()]; 

         b-&amp;gt;is_empty = false; 
         b-&amp;gt;size = building_id.size(); 

         for (int i = 0; i &amp;lt; building_id.size(); i++) 
         { 
            b&lt;I&gt;.id = const_cast&amp;lt;char*&amp;gt;(building_id&lt;I&gt;.c_str()); 
            b&lt;I&gt;.name = const_cast&amp;lt;char*&amp;gt;(building_name&lt;I&gt;.c_str()); 
         } 
         *building_data = b; 
      } 
      } 
     }&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

I believe the error occurred because of the delete[] operator overridden by API.&lt;BR /&gt;
My code separately (in exe) works correctly&lt;BR /&gt;
Please give me an advice to solve this problem</description>
      <pubDate>Mon, 02 Mar 2015 09:47:40 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249862#M5466</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-03-02T09:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORTANT! delete[] operator doesn't work</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249863#M5467</link>
      <description>&lt;BLOCKQUOTE&gt;Oleg wrote:&lt;BR /&gt;I think global new and delete overriden by API.&lt;BR /&gt;
May be ::delete[] building_data will work;&lt;BR /&gt;
&lt;BR /&gt;
But actually it is poor DLL design. &lt;BR /&gt;
You need do and export function from DLL like &lt;BR /&gt;
release_building_info(Building *building_data[])&lt;BR /&gt;
and free the memory.&lt;/BLOCKQUOTE&gt;

I think so, global new and delete overridden by API&lt;BR /&gt;
It crash also when I call ::delete[]&lt;BR /&gt;
&lt;BR /&gt;
What you mean ?&lt;BR /&gt;
&amp;gt;But actually it is poor DLL design. &lt;BR /&gt;
&amp;gt;You need do and export function from DLL like &lt;BR /&gt;
&amp;gt;release_building_info(Building *building_data[])&lt;BR /&gt;
&amp;gt;and free the memory&lt;BR /&gt;
&lt;BR /&gt;
I do allocated in dll and delete in add-on code.</description>
      <pubDate>Mon, 02 Mar 2015 09:52:25 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249863#M5467</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-03-02T09:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORTANT! delete[] operator doesn't work</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249864#M5468</link>
      <description>&lt;BLOCKQUOTE&gt;ggiloyan wrote:&lt;BR /&gt;
I do allocated in dll and delete in add-on code.&lt;/BLOCKQUOTE&gt;

You need both to allocate and to free in dll.&lt;BR /&gt;
&lt;BR /&gt;
Implement a function in dll like this:&lt;BR /&gt;
&lt;BR /&gt;
_declspec(dllexport) void release_building_info(Building *building_data[])&lt;BR /&gt;
{&lt;BR /&gt;
  delete [] building data;&lt;BR /&gt;
}	&lt;BR /&gt;
&lt;BR /&gt;
In addon code insted delete[] call release_building_info</description>
      <pubDate>Mon, 02 Mar 2015 10:04:10 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249864#M5468</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2015-03-02T10:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORTANT! delete[] operator doesn't work</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249865#M5469</link>
      <description>&lt;BLOCKQUOTE&gt;Oleg wrote:&lt;BR /&gt;&lt;BLOCKQUOTE&gt;ggiloyan wrote:&lt;BR /&gt;
I do allocated in dll and delete in add-on code.&lt;/BLOCKQUOTE&gt;

You need both to allocate and to free in dll.&lt;BR /&gt;
&lt;BR /&gt;
Implement a function in dll like this:&lt;BR /&gt;
&lt;BR /&gt;
_declspec(dllexport) void release_building_info(Building *building_data[])&lt;BR /&gt;
{&lt;BR /&gt;
  delete [] building data;&lt;BR /&gt;
}	&lt;BR /&gt;
&lt;BR /&gt;
In addon code insted delete[] call release_building_info&lt;/BLOCKQUOTE&gt;

Thank for the help.&lt;BR /&gt;
It works correctly by this way&lt;BR /&gt;

&lt;PRE&gt;__declspec(dllexport) void release_building(Building *building_data[], int size)
	{
		for (int i = 0; i &amp;lt; size; ++i)
		{
			delete[] building_data&lt;I&gt;;
		}
	}&lt;/I&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Mar 2015 08:27:10 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/SOLVED-IMPORTANT-delete-operator-doesn-t-work/m-p/249865#M5469</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-03-03T08:27:10Z</dc:date>
    </item>
  </channel>
</rss>

