<?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[Output aendert sich mit dem Auruf ueber Valgrind]]></title><description><![CDATA[<p>Hallo.</p>
<p>Das Verhalten meines Programms aendert sich mit/ohne Aufruf ueber Valgrinds. Es handelt sich dabei eigentlich nur um ein reines Testprogramm (also es macht nichts Sinnvolles).</p>
<pre><code class="language-cpp">class TestClass
{
private:
  static std::list&lt;TestClass*&gt; self_list_;
public:
  TestClass()
  {
    self_list_.push_back(this);
  }
  ~TestClass()
  {
  }
};

void testClass()
{
  TestClass *ptr = new TestClass;
  delete ptr;
  ptr = 0;
}
</code></pre>
<p>Ausgabe ohne Valgrind:</p>
<pre><code>Output (ohne valgrind):
--------------------------------------------------
::new(size:640)
Memory allocated.
ret(block:0x804b008)
--------------------------------------------------
::new(size:1)
Memory allocated.
ret(block:0x804b290)
--------------------------------------------------
::delete(base_ptr:0x804b290)
Memory freed.
ret(void)
</code></pre>
<p>Ausgabe mit Valgrind:</p>
<pre><code>--------------------------------------------------
::new(size:12)
Memory allocated.
ret(block:0x4779028)
--------------------------------------------------
::new(size:1)
Memory allocated.
ret(block:0x4779068)
--------------------------------------------------
::new(size:12)
Memory allocated.
ret(block:0x47790a0)
--------------------------------------------------
::delete(base_ptr:0x4779068)
Memory freed.
ret(void)
--------------------------------------------------
::delete(base_ptr:0x47790a0)
Memory freed.
ret(void)
--------------------------------------------------
::delete(base_ptr:0x4779028)
Memory freed.
ret(void)
</code></pre>
<p>Das sollte alles wesentliche gewesen sein.</p>
<p>Eventuell will auch jmd das selbst ausprobieren, dafuer hab ich alles schnell mal in ein File kopiert.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;list&gt;

using std::cout;
using std::endl;
using std::bad_alloc;
using std::list;

namespace
{
  size_t max_alloc_block_size_ = 1000;
};

void *operator new(size_t size) throw(std::bad_alloc)
{
  cout &lt;&lt; &quot;--------------------------------------------------&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;::new(size:&quot; &lt;&lt; size &lt;&lt; &quot;)&quot; &lt;&lt; endl;

  if (size &gt; max_alloc_block_size_)
  {
    throw bad_alloc();
  }

  void *block = malloc(size);

  if (!block)
  {
    throw bad_alloc();
  }

  cout &lt;&lt; &quot;Memory allocated.&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;ret(block:&quot; &lt;&lt; block &lt;&lt; &quot;)&quot; &lt;&lt; endl;

  return (block);
}

void operator delete(void *base_ptr) throw()
{
  cout &lt;&lt; &quot;--------------------------------------------------&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;::delete(base_ptr:&quot; &lt;&lt; base_ptr &lt;&lt; &quot;)&quot; &lt;&lt; endl;

  if (!base_ptr)
  {
    return;
  }

  free(base_ptr);

  cout &lt;&lt; &quot;Memory freed.&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;ret(void)&quot; &lt;&lt; endl;
}

class TestClass
{
private:
  static list&lt;TestClass*&gt; self_list_;
public:
  TestClass()
  {
    self_list_.push_back(this);
  }
  ~TestClass()
  {
  }
};

list&lt;TestClass*&gt; TestClass::self_list_;

void testClass()
{
  TestClass *ptr = new TestClass;
  delete ptr;
  ptr = 0;
}

int main(int argc, char *argv[])
{
  testClass();

  return (0);
}
</code></pre>
<p>Ich hoffe mir kann das jmd erklaeren.</p>
<p>Vielen Danke und<br />
mfg mythso_</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/136705/output-aendert-sich-mit-dem-auruf-ueber-valgrind</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 13:07:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/136705.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 12 Feb 2006 16:09:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Output aendert sich mit dem Auruf ueber Valgrind on Sun, 12 Feb 2006 16:09:09 GMT]]></title><description><![CDATA[<p>Hallo.</p>
<p>Das Verhalten meines Programms aendert sich mit/ohne Aufruf ueber Valgrinds. Es handelt sich dabei eigentlich nur um ein reines Testprogramm (also es macht nichts Sinnvolles).</p>
<pre><code class="language-cpp">class TestClass
{
private:
  static std::list&lt;TestClass*&gt; self_list_;
public:
  TestClass()
  {
    self_list_.push_back(this);
  }
  ~TestClass()
  {
  }
};

void testClass()
{
  TestClass *ptr = new TestClass;
  delete ptr;
  ptr = 0;
}
</code></pre>
<p>Ausgabe ohne Valgrind:</p>
<pre><code>Output (ohne valgrind):
--------------------------------------------------
::new(size:640)
Memory allocated.
ret(block:0x804b008)
--------------------------------------------------
::new(size:1)
Memory allocated.
ret(block:0x804b290)
--------------------------------------------------
::delete(base_ptr:0x804b290)
Memory freed.
ret(void)
</code></pre>
<p>Ausgabe mit Valgrind:</p>
<pre><code>--------------------------------------------------
::new(size:12)
Memory allocated.
ret(block:0x4779028)
--------------------------------------------------
::new(size:1)
Memory allocated.
ret(block:0x4779068)
--------------------------------------------------
::new(size:12)
Memory allocated.
ret(block:0x47790a0)
--------------------------------------------------
::delete(base_ptr:0x4779068)
Memory freed.
ret(void)
--------------------------------------------------
::delete(base_ptr:0x47790a0)
Memory freed.
ret(void)
--------------------------------------------------
::delete(base_ptr:0x4779028)
Memory freed.
ret(void)
</code></pre>
<p>Das sollte alles wesentliche gewesen sein.</p>
<p>Eventuell will auch jmd das selbst ausprobieren, dafuer hab ich alles schnell mal in ein File kopiert.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;list&gt;

using std::cout;
using std::endl;
using std::bad_alloc;
using std::list;

namespace
{
  size_t max_alloc_block_size_ = 1000;
};

void *operator new(size_t size) throw(std::bad_alloc)
{
  cout &lt;&lt; &quot;--------------------------------------------------&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;::new(size:&quot; &lt;&lt; size &lt;&lt; &quot;)&quot; &lt;&lt; endl;

  if (size &gt; max_alloc_block_size_)
  {
    throw bad_alloc();
  }

  void *block = malloc(size);

  if (!block)
  {
    throw bad_alloc();
  }

  cout &lt;&lt; &quot;Memory allocated.&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;ret(block:&quot; &lt;&lt; block &lt;&lt; &quot;)&quot; &lt;&lt; endl;

  return (block);
}

void operator delete(void *base_ptr) throw()
{
  cout &lt;&lt; &quot;--------------------------------------------------&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;::delete(base_ptr:&quot; &lt;&lt; base_ptr &lt;&lt; &quot;)&quot; &lt;&lt; endl;

  if (!base_ptr)
  {
    return;
  }

  free(base_ptr);

  cout &lt;&lt; &quot;Memory freed.&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;ret(void)&quot; &lt;&lt; endl;
}

class TestClass
{
private:
  static list&lt;TestClass*&gt; self_list_;
public:
  TestClass()
  {
    self_list_.push_back(this);
  }
  ~TestClass()
  {
  }
};

list&lt;TestClass*&gt; TestClass::self_list_;

void testClass()
{
  TestClass *ptr = new TestClass;
  delete ptr;
  ptr = 0;
}

int main(int argc, char *argv[])
{
  testClass();

  return (0);
}
</code></pre>
<p>Ich hoffe mir kann das jmd erklaeren.</p>
<p>Vielen Danke und<br />
mfg mythso_</p>
]]></description><link>https://www.c-plusplus.net/forum/post/992388</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/992388</guid><dc:creator><![CDATA[mythos_]]></dc:creator><pubDate>Sun, 12 Feb 2006 16:09:09 GMT</pubDate></item><item><title><![CDATA[Reply to Output aendert sich mit dem Auruf ueber Valgrind on Sun, 12 Feb 2006 16:46:18 GMT]]></title><description><![CDATA[<p>Kann es sein, dass Du das Programm mit zwei unterschiedlichen Implementierungen von std::list übersetzt hast. Einmal mit Debug und einmal ohne könnte schon reichen, um diesen Effekt zu erzeugen.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/992415</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/992415</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Sun, 12 Feb 2006 16:46:18 GMT</pubDate></item></channel></rss>