title: Updating values in cli/c++ array<Object^> causes extensive Garbage Collection
body: <p>The Method below is used to transport native data into managed data
  structures. The AppendDataToChannel method does assign the created arrays
  to bigger structures.</p>
  
  <p>What i am seeing now is that this methods execution time is 50% garbage
  collection. As time is very critical for me i have to get rid of that.</p>
  
  <p>My assumption is that the "->SetValue" in that array is causing the
  value which is overwritten to be "garbage collected". Is there a fast way to 
  update the values in the array without causing such behaviour?
  (there are thousands of calls to ->SetValue)</p>
  
  <p><a href="https://i.stack.imgur.com/P27jH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P27jH.png" alt="Trace of execution (method is called multiple times)"></a>
  Thanks in advance,
  Nicolas</p>
  
  <pre><code>template &lt;typename Tnative, typename Tmanaged&gt;
  ChannelGroupData    ^   NativeToManaged(I_ChannelGroup &amp;aChannelGroup, unsigned int index, unsigned int count)
  {
      std::map&lt; std::string, std::vector&lt;Tnative&gt; &gt; v;
      aChannelGroup.GetData(v, index, count);
  
      ChannelGroupData^ result = gcnew ChannelGroupData(v.size());
  
      for (std::map&lt; std::string, std::vector&lt;Tnative&gt; &gt;::const_iterator cMIt = v.begin(); cMIt != v.end(); ++cMIt)
      {   
          std::string channelObjectPath(cMIt-&gt;first);
          I_Channel *aChannel = aChannelGroup.GetChannelByObjectPath(channelObjectPath);
          if (aChannel != NULL)
          {
              unsigned int vSize (cMIt-&gt;second.size());
              DataType aType = static_cast&lt;DataType&gt;(aChannel-&gt;GetDataType());
              int iIndex (0);
              const std::vector&lt;Tnative&gt; *pChannelDataV (&amp;cMIt-&gt;second);
              array&lt;Tmanaged&gt;^ vResult = gcnew array&lt;Tmanaged&gt;(pChannelDataV-&gt;size());
              for (std::vector&lt;Tnative&gt;::const_iterator cDIt = pChannelDataV-&gt;begin(); cDIt != pChannelDataV-&gt;end(); ++cDIt, ++iIndex)
              {
                  vResult-&gt;SetValue((Tmanaged)(gcnew Tnative(*cDIt)), iIndex);
              }
              result-&gt;AppendDataToChannel(gcnew System::String(channelObjectPath.c_str()), vResult,static_cast&lt;int&gt;( aType), iIndex);
              delete aChannel;
          }
      }
      return result;
  }
  </code></pre>