<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[unhandled exception bzw. access violation bei MEMCPY]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich hätte da noch eine Frage <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
Und zwar bekomme ich bei dem unten aufgeführten Code leider immer Programmabstürze an der Stelle &quot;memcpy&quot; mit folgender Meldung:</p>
<blockquote>
<p>Unhandled exception at 0x6af5d57c in Test.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd.</p>
</blockquote>
<p>Bin für jede Hilfe sehr dankbar!<br />
V.K.</p>
<pre><code class="language-cpp">//....
  int i;
  cRGB24Pixel	*pbImgData,**pImgAll;
  pImgAll = new cRGB24Pixel *[10];

  for (i=0;i&lt;10;i++)
  {
    //...
    pbImgData = (cRGB24Pixel*) pActiveBuf-&gt;getPtr(); // hier wird ein Bild in pbImgData abgelegt 
    memcpy(pImgAll[i],pbImgData,grabber.getAcqSizeMaxY()*grabber.getAcqSizeMaxX()*sizeof(cRGB24Pixel)); // jenes Bild soll dann in einem Array gespeichert werden, 
// damit es nicht beim nächsten Durchgang der for-Schleife wieder überschrieben wird
  }
//....
  delete pImgAll;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/235358/unhandled-exception-bzw-access-violation-bei-memcpy</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 05:42:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/235358.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 28 Feb 2009 21:30:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to unhandled exception bzw. access violation bei MEMCPY on Sat, 28 Feb 2009 21:30:05 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich hätte da noch eine Frage <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
Und zwar bekomme ich bei dem unten aufgeführten Code leider immer Programmabstürze an der Stelle &quot;memcpy&quot; mit folgender Meldung:</p>
<blockquote>
<p>Unhandled exception at 0x6af5d57c in Test.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd.</p>
</blockquote>
<p>Bin für jede Hilfe sehr dankbar!<br />
V.K.</p>
<pre><code class="language-cpp">//....
  int i;
  cRGB24Pixel	*pbImgData,**pImgAll;
  pImgAll = new cRGB24Pixel *[10];

  for (i=0;i&lt;10;i++)
  {
    //...
    pbImgData = (cRGB24Pixel*) pActiveBuf-&gt;getPtr(); // hier wird ein Bild in pbImgData abgelegt 
    memcpy(pImgAll[i],pbImgData,grabber.getAcqSizeMaxY()*grabber.getAcqSizeMaxX()*sizeof(cRGB24Pixel)); // jenes Bild soll dann in einem Array gespeichert werden, 
// damit es nicht beim nächsten Durchgang der for-Schleife wieder überschrieben wird
  }
//....
  delete pImgAll;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1672178</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1672178</guid><dc:creator><![CDATA[VerbalKint]]></dc:creator><pubDate>Sat, 28 Feb 2009 21:30:05 GMT</pubDate></item><item><title><![CDATA[Reply to unhandled exception bzw. access violation bei MEMCPY on Sat, 28 Feb 2009 22:35:07 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">pImgAll = new cRGB24Pixel *[10];
</code></pre>
<p>Du erstellst in dieser Zeile auf einem ZeigerZeiger ein Array aus zeigern, das is zwars chön, aber die Zeigen erstmal nur irgendwohin, und genau dahin will memcpy schreiben, das kann nicht gut gehen. Jedes Arrayelement ist jetzt ein Zeiger und müsste einzelln erstmal mit new noch Speicher zugewiesen bekommen, dementsprechend musst du dann auch am ende mit delete alles Rückwerts abbauen, also erst den Speicher der Zeiger aus dem Array und danach das Array selbst.</p>
<p>Access Violations bedueten im übrigen immer das der Zielort nicht beschrieben werden kann. Und pro Zeigertiefe soltest du eon p als Prefix anhängen, dh also für ZeigerZeiger pp, das macht es etwas übersichtlicher.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1672203</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1672203</guid><dc:creator><![CDATA[Xebov]]></dc:creator><pubDate>Sat, 28 Feb 2009 22:35:07 GMT</pubDate></item><item><title><![CDATA[Reply to unhandled exception bzw. access violation bei MEMCPY on Sun, 01 Mar 2009 08:27:48 GMT]]></title><description><![CDATA[<p>Hallo.</p>
<p>Danke für die Antwort! Deinen Vorschlag hatte ich zuvor auch schon ausprobiert, sie wie ich es unten aufgeschrieben habe. Leider hat das auch nicht geklappt. An der gleichen Stelle kommt die gleiche Fehlermeldung:</p>
<blockquote>
<p>Unhandled exception at 0x0041299e in Test.exe: 0xC0000005: Access violation reading location 0x00000000.</p>
</blockquote>
<p>Danke für weitere Hilfe!<br />
V.K.</p>
<pre><code class="language-cpp">int i;
  cRGB24Pixel	*pbImgData,**ppImgAll;
  ppImgAll = new cRGB24Pixel *[10];

  for (i=0;i&lt;10;i++)
  {
    //...
    ppImgAll[i] = new cRGB24Pixel [grabber.getAcqSizeMaxY()*grabber.getAcqSizeMaxX()];
    pbImgData = (cRGB24Pixel*) pActiveBuf-&gt;getPtr();
    memcpy(ppImgAll[i],pbImgData,grabber.getAcqSizeMaxY()*grabber.getAcqSizeMaxX()*sizeof(cRGB24Pixel));
  }
  for (i=0;i&lt;10;i++)
    delete[] ppImgAll[i];
  delete ppImgAll;
</code></pre>
<p><strong>EDIT:</strong><br />
Habe den Fehler selber gefunden. Die Werte grabber.getAcqSizeMaxY() und grabber.getAcqSizeMaxX() sind long Werte. Ich habe sie jetzt auf int gecastet und es funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1672271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1672271</guid><dc:creator><![CDATA[VerbalKint]]></dc:creator><pubDate>Sun, 01 Mar 2009 08:27:48 GMT</pubDate></item><item><title><![CDATA[Reply to unhandled exception bzw. access violation bei MEMCPY on Sun, 01 Mar 2009 09:00:46 GMT]]></title><description><![CDATA[<p>Da kann ich nur <strong>std::vector&lt;T&gt;</strong> empfehlen.<br />
Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1672276</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1672276</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Sun, 01 Mar 2009 09:00:46 GMT</pubDate></item><item><title><![CDATA[Reply to unhandled exception bzw. access violation bei MEMCPY on Sun, 01 Mar 2009 22:22:29 GMT]]></title><description><![CDATA[<p>Auch <code>memcpy()</code> wird in C++ sehr selten verwendet. Für solche Sachen gibts die STL mit ihren Containern und Algorithmen wie <code>std::copy()</code> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1672557</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1672557</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 01 Mar 2009 22:22:29 GMT</pubDate></item></channel></rss>