<?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[std::list.clear() schlägt fehl]]></title><description><![CDATA[<p>Hallo Forum!</p>
<p>Ich habe ein Problem aufräumen von meinem Speicher.<br />
Ein poste mal zu erst die Klassen, Vektoren bzw. Listen, die in der DLL bzw. im Header dazu deklariert habe.<br />
Als Compiler setzte ich Microsoft Visual C++ 2005 ein.</p>
<pre><code class="language-cpp">#ifdef PARSER_EXPORTS
#define PARSER_API __declspec(dllexport)
#else
#define PARSER_API __declspec(dllimport)
#endif /* #ifdef PARSER_EXPORTS */
</code></pre>
<p>Ich habe den folgenden Vektor:</p>
<pre><code class="language-cpp">typedef std::vector&lt;unsigned long&gt; VECTORUNIONS
                               , *PVECTORUNIONS;
</code></pre>
<p>Daneben die folgende Klasse, die mir Probleme bereitet:</p>
<pre><code class="language-cpp">class CSTATIONENTRY
{
private:
             std::string   m_sStationName;
             unsigned long m_ulLogID;
             VECTORUNIONS  m_VecUnions;
             unsigned long m_ulLineNum;
public:
  PARSER_API               CSTATIONENTRY       ( void );
  PARSER_API              ~CSTATIONENTRY       ( void );
  PARSER_API std::string   GetStationName      ( void ) const ;
  PARSER_API bool          SetStationName      ( const std::string   &amp;sStationName );
  PARSER_API unsigned long GetLogID            ( void ) const ;
  PARSER_API bool          SetLogID            ( const unsigned long  ulLogID );
  PARSER_API bool          GetUnions           (       VECTORUNIONS * pVectorUnions ) const ;
  PARSER_API bool          SetUnions           ( const VECTORUNIONS * 
                                                                          const pVectorUnions
                                               );
  PARSER_API unsigned long GetLineNum          ( void ) const ;
  PARSER_API bool          SetLineNum          ( const unsigned long  ulLineNum );

  PARSER_API bool          ResetAllData        ( void );
}; /* class CSTATIONENTRY */
</code></pre>
<p>Dann folgt noch ein typedef:</p>
<pre><code class="language-cpp">typedef std::list&lt;CSTATIONENTRY&gt; STATIONLIST
                             , *PSTATIONLIST;
</code></pre>
<p>Und noch eine Klasse (leicht gekürzt):</p>
<pre><code class="language-cpp">class CParser
{
private:
                           CSTATIONENTRY
                                     m_Station;
                           STATIONLIST
                                     m_listStations;
public:
  PARSER_API               CNetkondat_Parser   ( void );
  PARSER_API              ~CNetkondat_Parser   ( void );

  PARSER_API unsigned long GetStationList      ( const PSTATIONLIST pStationList ) const ;
}; /* class CParser */
</code></pre>
<p>Die Funktion &quot;GetStationList&quot; ist wie folgt implementiert:</p>
<pre><code class="language-cpp">unsigned long CParser::GetStationList( const PSTATIONLIST pStationList ) const
{
  unsigned long               ulReturn    = 0;
  STATIONLIST::const_iterator StationIter = m_listStations.begin();

  pStationList-&gt;clear();

  for ( StationIter  = m_listStations.begin()
      ; StationIter != m_listStations.end()
      ; ++StationIter
      )
  {
    pStationList-&gt;push_back( (*StationIter) );
  } /* for ( StationIter = m_listStations.begin(); ... ) */

  return ( ulReturn );
} /* GetStationList( const PSTATIONLIST pStationList ) */
</code></pre>
<p>Die Daten werden über die Folgende Methode in die Liste eingefügt:</p>
<pre><code class="language-cpp">m_listStations.push_back( m_Station );
</code></pre>
<p>&quot;m_Station&quot; ist dabei wie oben ersichtlich ein privater Member der Klasse &quot;CParser&quot;, die immer wieder aufs neue mit Daten gefuellt wird.</p>
<p>So, dann ganze ist eine DLL gegossen und klappt auch so weit. Aus meinem Programm komme ich an die Elemente in der List durch den folgenden Aufruf einer Methode einer weiteren Klasse, die nicht in der DLL liegt, zugreifen. Implementierung s.o.</p>
<pre><code class="language-cpp">m_pNetkondatParser-&gt;GetStationList( &amp;m_listStationsIn );
</code></pre>
<p>Ich kann auch wunderbar auf die Elemente in Liste zugreifen.<br />
Nur jetzt kommen wir zu meinem Problem, wenn ich die Liste &quot;m_listNetkondatStationsIn&quot; die ein private Memember ist leeren möchte, schmiert mir das Programm mit einem Speicherfehler ab.<br />
Also der Aufruf &quot;m_listStationsIn.clear()&quot; verabschiedet sich dann. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Leider weiß ich im Moment nicht weiter und hoffe auf Hilfe von euch.<br />
Danke schon mal.</p>
<p>MfG</p>
<p>naujo</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/198170/std-list-clear-schlägt-fehl</link><generator>RSS for Node</generator><lastBuildDate>Thu, 01 Oct 2026 20:28:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/198170.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 Nov 2007 10:24:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::list.clear() schlägt fehl on Mon, 19 Nov 2007 10:24:08 GMT]]></title><description><![CDATA[<p>Hallo Forum!</p>
<p>Ich habe ein Problem aufräumen von meinem Speicher.<br />
Ein poste mal zu erst die Klassen, Vektoren bzw. Listen, die in der DLL bzw. im Header dazu deklariert habe.<br />
Als Compiler setzte ich Microsoft Visual C++ 2005 ein.</p>
<pre><code class="language-cpp">#ifdef PARSER_EXPORTS
#define PARSER_API __declspec(dllexport)
#else
#define PARSER_API __declspec(dllimport)
#endif /* #ifdef PARSER_EXPORTS */
</code></pre>
<p>Ich habe den folgenden Vektor:</p>
<pre><code class="language-cpp">typedef std::vector&lt;unsigned long&gt; VECTORUNIONS
                               , *PVECTORUNIONS;
</code></pre>
<p>Daneben die folgende Klasse, die mir Probleme bereitet:</p>
<pre><code class="language-cpp">class CSTATIONENTRY
{
private:
             std::string   m_sStationName;
             unsigned long m_ulLogID;
             VECTORUNIONS  m_VecUnions;
             unsigned long m_ulLineNum;
public:
  PARSER_API               CSTATIONENTRY       ( void );
  PARSER_API              ~CSTATIONENTRY       ( void );
  PARSER_API std::string   GetStationName      ( void ) const ;
  PARSER_API bool          SetStationName      ( const std::string   &amp;sStationName );
  PARSER_API unsigned long GetLogID            ( void ) const ;
  PARSER_API bool          SetLogID            ( const unsigned long  ulLogID );
  PARSER_API bool          GetUnions           (       VECTORUNIONS * pVectorUnions ) const ;
  PARSER_API bool          SetUnions           ( const VECTORUNIONS * 
                                                                          const pVectorUnions
                                               );
  PARSER_API unsigned long GetLineNum          ( void ) const ;
  PARSER_API bool          SetLineNum          ( const unsigned long  ulLineNum );

  PARSER_API bool          ResetAllData        ( void );
}; /* class CSTATIONENTRY */
</code></pre>
<p>Dann folgt noch ein typedef:</p>
<pre><code class="language-cpp">typedef std::list&lt;CSTATIONENTRY&gt; STATIONLIST
                             , *PSTATIONLIST;
</code></pre>
<p>Und noch eine Klasse (leicht gekürzt):</p>
<pre><code class="language-cpp">class CParser
{
private:
                           CSTATIONENTRY
                                     m_Station;
                           STATIONLIST
                                     m_listStations;
public:
  PARSER_API               CNetkondat_Parser   ( void );
  PARSER_API              ~CNetkondat_Parser   ( void );

  PARSER_API unsigned long GetStationList      ( const PSTATIONLIST pStationList ) const ;
}; /* class CParser */
</code></pre>
<p>Die Funktion &quot;GetStationList&quot; ist wie folgt implementiert:</p>
<pre><code class="language-cpp">unsigned long CParser::GetStationList( const PSTATIONLIST pStationList ) const
{
  unsigned long               ulReturn    = 0;
  STATIONLIST::const_iterator StationIter = m_listStations.begin();

  pStationList-&gt;clear();

  for ( StationIter  = m_listStations.begin()
      ; StationIter != m_listStations.end()
      ; ++StationIter
      )
  {
    pStationList-&gt;push_back( (*StationIter) );
  } /* for ( StationIter = m_listStations.begin(); ... ) */

  return ( ulReturn );
} /* GetStationList( const PSTATIONLIST pStationList ) */
</code></pre>
<p>Die Daten werden über die Folgende Methode in die Liste eingefügt:</p>
<pre><code class="language-cpp">m_listStations.push_back( m_Station );
</code></pre>
<p>&quot;m_Station&quot; ist dabei wie oben ersichtlich ein privater Member der Klasse &quot;CParser&quot;, die immer wieder aufs neue mit Daten gefuellt wird.</p>
<p>So, dann ganze ist eine DLL gegossen und klappt auch so weit. Aus meinem Programm komme ich an die Elemente in der List durch den folgenden Aufruf einer Methode einer weiteren Klasse, die nicht in der DLL liegt, zugreifen. Implementierung s.o.</p>
<pre><code class="language-cpp">m_pNetkondatParser-&gt;GetStationList( &amp;m_listStationsIn );
</code></pre>
<p>Ich kann auch wunderbar auf die Elemente in Liste zugreifen.<br />
Nur jetzt kommen wir zu meinem Problem, wenn ich die Liste &quot;m_listNetkondatStationsIn&quot; die ein private Memember ist leeren möchte, schmiert mir das Programm mit einem Speicherfehler ab.<br />
Also der Aufruf &quot;m_listStationsIn.clear()&quot; verabschiedet sich dann. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Leider weiß ich im Moment nicht weiter und hoffe auf Hilfe von euch.<br />
Danke schon mal.</p>
<p>MfG</p>
<p>naujo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405762</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405762</guid><dc:creator><![CDATA[naujo]]></dc:creator><pubDate>Mon, 19 Nov 2007 10:24:08 GMT</pubDate></item><item><title><![CDATA[Reply to std::list.clear() schlägt fehl on Mon, 19 Nov 2007 10:28:31 GMT]]></title><description><![CDATA[<p>Ist die DLL gegen die gleiche Laufzeit gelinkt wie das Program welches die DLL nutzt? (Debug vs. non-Debug, Threaded vs. non-Threaded usw)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405765</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405765</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Mon, 19 Nov 2007 10:28:31 GMT</pubDate></item><item><title><![CDATA[Reply to std::list.clear() schlägt fehl on Mon, 19 Nov 2007 10:46:36 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Also ich habe noch mal alle Einstellungen in der IDE mit einander verglichen.<br />
Und sie sind gleich, so weit es möglich ist.</p>
<p>MfG</p>
<p>naujo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405777</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405777</guid><dc:creator><![CDATA[naujo]]></dc:creator><pubDate>Mon, 19 Nov 2007 10:46:36 GMT</pubDate></item><item><title><![CDATA[Reply to std::list.clear() schlägt fehl on Mon, 19 Nov 2007 11:25:16 GMT]]></title><description><![CDATA[<p>Hi</p>
<p>1.)<br />
Bei</p>
<blockquote>
<p>pStationList-&gt;clear();</p>
</blockquote>
<p>wird bei jedem Eintrag der dtor der CSTATIONENTRY Objekte aufgerufen. Kannst Du soweit noch debuggen, oder gibts vorher schon Ärger?</p>
<p>2.)<br />
Ist es richtig, dass alles gut geht, wenn Du zuerst</p>
<pre><code class="language-cpp">m_listStationsIn.clear()
</code></pre>
<p>und dann</p>
<pre><code class="language-cpp">m_pNetkondatParser-&gt;GetStationList( &amp;m_listStationsIn );
</code></pre>
<p>aufrufst, wo bei in GetStationList(..) kein clear auf den vector mehr gemacht wird?</p>
<p>Gruss simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405803</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405803</guid><dc:creator><![CDATA[simon.gysi]]></dc:creator><pubDate>Mon, 19 Nov 2007 11:25:16 GMT</pubDate></item><item><title><![CDATA[Reply to std::list.clear() schlägt fehl on Mon, 19 Nov 2007 11:55:04 GMT]]></title><description><![CDATA[<p>Hallo simon!</p>
<p>zu 1)</p>
<p>Die Eingabelist bereits leer und das klappt noch. Der Aufruf ist nur zur Sicherheit, damit die Liste auch wirklich leer ist.</p>
<p>zu 2)</p>
<p>Meine Probleme mit dem clear tauchen erst auf, wenn ich die Funktion</p>
<pre><code class="language-cpp">m_pNetkondatParser-&gt;GetStationList( &amp;m_listStationsIn );
</code></pre>
<p>Aufgerufen habe und dann eben ein</p>
<pre><code class="language-cpp">m_listStationsIn.clear()
</code></pre>
<p>machen möchte. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Vorher geht es gut, da die Liste leer ist. Und nur durch die oben genannte Funktion gefüllt wird.</p>
<p>Der Destor wird immer angelaufen und am Ende vom leeren Destor kommt dann der Fehler. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>MfG</p>
<p>naujo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405821</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405821</guid><dc:creator><![CDATA[naujo]]></dc:creator><pubDate>Mon, 19 Nov 2007 11:55:04 GMT</pubDate></item><item><title><![CDATA[Reply to std::list.clear() schlägt fehl on Mon, 19 Nov 2007 12:55:12 GMT]]></title><description><![CDATA[<p>Wird dort Speicher, der in der DLL reserviert wurde, im Kontext der Anwendung freigegeben, bzw. umgekehrt?</p>
<p>Falls ja ist das das Problem. Beide haben einen eigenen Heap.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405858</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405858</guid><dc:creator><![CDATA[7H3 N4C3R]]></dc:creator><pubDate>Mon, 19 Nov 2007 12:55:12 GMT</pubDate></item><item><title><![CDATA[Reply to std::list.clear() schlägt fehl on Mon, 19 Nov 2007 13:06:52 GMT]]></title><description><![CDATA[<p>Hi 7H3 N4C3R!</p>
<p>Wie oben beschrieben wird in der DLL ein &quot;push_back()&quot; gemacht.<br />
Aber jetzt wird es mir klar, das es so nicht gehen kann <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> wenn die Heaps getrennt sind. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
<p>Also es wird im Kontext der DLL der Speicher reserviert. Dann ist es natürlich klar, dass die Freigabe des Speichers im Kontext der Anwendung fehlschlägt.</p>
<p>Dann werde ich mir mal eine andere Funktion ein fallen lassen müssen, damit es so funktioniert, wie ich mir das vorstelle.</p>
<p>Ich danke euch für eure Unterstützung und die Lösungsfindung bei meinem Problem!</p>
<p>MfG</p>
<p>naujo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1405872</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1405872</guid><dc:creator><![CDATA[naujo]]></dc:creator><pubDate>Mon, 19 Nov 2007 13:06:52 GMT</pubDate></item></channel></rss>