<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NeoEGM.com &#187; Memory Leaks</title>
	<atom:link href="http://www.neoegm.com/tag/memory-leaks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.neoegm.com</link>
	<description>Knowledge is inside</description>
	<lastBuildDate>Mon, 08 Jul 2024 05:38:01 +0000</lastBuildDate>
	<language>es-ES</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.39</generator>
	<item>
		<title>Clase Lista simple para C++</title>
		<link>http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/</link>
		<comments>http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 20:55:36 +0000</pubDate>
		<dc:creator><![CDATA[NeoEGM]]></dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Console]]></category>
		<category><![CDATA[Download]]></category>
		<category><![CDATA[Easy]]></category>
		<category><![CDATA[Exercise]]></category>
		<category><![CDATA[Freeware]]></category>
		<category><![CDATA[GNU GPL]]></category>
		<category><![CDATA[Include]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[Memory Leaks]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Portable]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[Teaching]]></category>
		<category><![CDATA[wxDev]]></category>

		<guid isPermaLink="false">http://www.neoegm.com/?p=976</guid>
		<description><![CDATA[Tal como publiqué hace algunos días la Clase String Simple para C++ como un ejercicio de aprendizaje de C++, ahora estoy liberando una Clase Lista simple para C++. La librería standard tiene una clase list. Pero, mientras se está aprendiendo, es una buena idea saber cómo poder desarrollar tu propia clase list. Esa es la [&#8230;]<div class='yarpp-related-rss'>
<strong>
Related posts:<ol>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-string-class/" rel="bookmark" title="Clase String simple para C++">Clase String simple para C++ </a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" rel="bookmark" title="cppMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C++">cppMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C++ </a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/control-de-asistencia/" rel="bookmark" title="Control de Asistencia">Control de Asistencia </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Tal como publiqué hace algunos días la <a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-string-class/">Clase String Simple para C++</a> como un ejercicio de aprendizaje de C++, ahora estoy liberando una <strong>Clase Lista simple para C++</strong>.</p>
<p>La librería standard tiene una clase <em>list</em>. Pero, mientras se está aprendiendo, es una buena idea saber cómo poder desarrollar tu propia clase <em>list</em>.</p>
<p>Esa es la razón por la que hice la clase <em>List</em>. No está pensada para proyectos profesionales (para ellos, deberías utilizar la <em>list</em> de la librería standard), sino como una ayuda para aprender C++.</p>
<pre class="brush: cpp; title: ; notranslate">
template &lt;class TYPE&gt;
class List
{
	/* ... */

public:
	//Construction and destruction
	List() { /* ... */ }
	~List() { /* ... */ }
	
	List(const List&amp; rlList) { /* ... */ }
	
	//Assignment operator
	List&amp; operator=(const List&amp; rlList);

	//Information
	int Length() { /* ... */ }
	bool Empty() { /* ... */ }

	//Element managing
	int Add(TYPE&amp; rtData);
	TYPE* Elem(int nPos);
	bool Delete(int nPos);
	void DeleteAll();
	
	//Search
	int Find(TYPE&amp; rItem, int nStartAt = 0);

	//Operadores
	TYPE&amp; operator[](int nPos) { /* ... */ }	//Elem
	int operator&lt;&lt;(TYPE&amp; rdData) { /* ... */ }	//Add

protected:
	void FreeList();
	void Init() { /* ... */ }
};

//Output
template &lt;class TYPE&gt;
std::ostream&amp; operator&lt;&lt;(std::ostream&amp; oStream, List&lt;TYPE&gt;&amp; rlList);
</pre>
<p><span id="more-976"></span></p>
<p>Este es un proyecto de ejemplo hecho para explicar la utilización de la clase <em>List</em>.</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;iostream&gt;
	using std::cout;
	using std::cin;
	using std::endl;

#include &quot;List.h&quot;
#include &quot;String.h&quot;

int main(int argc, char *argv[])
{
	cout &lt;&lt; &quot;List sample project&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;-------------------&quot; &lt;&lt; endl &lt;&lt; endl;


	//-----------------------------
	cout &lt;&lt; &quot;&gt; Creating a list of strings... An empty string finishes the list...&quot; &lt;&lt; endl &lt;&lt; endl;

	List&lt;String&gt; lStrings;
	String sTmp;
	
	do
	{
		cout &lt;&lt; &quot;&gt; String &quot; &lt;&lt; lStrings.Length()+1 &lt;&lt; &quot;: &quot;;
		cin &gt;&gt; sTmp;
		
		if (sTmp.Length())
			lStrings.Add(sTmp);
	} while (sTmp.Length());
	
	cout &lt;&lt; endl &lt;&lt; &quot;&gt; Entry finished. &quot; &lt;&lt; lStrings.Length() &lt;&lt; &quot; string(s) loaded.&quot; &lt;&lt; endl &lt;&lt; endl;
	
	cout &lt;&lt; &quot;&gt; Printing list...&quot; &lt;&lt; endl &lt;&lt; endl;
	
	cout &lt;&lt; lStrings;

	cout &lt;&lt; endl;
	//-----------------------------
	
	
	//-----------------------------
	do
	{
		cout &lt;&lt; &quot;&gt; Type a string to find in the list (exact match) [empty = end]: &quot;;
		cin &gt;&gt; sTmp;

		if (sTmp.Length())
		{
			int nFound = lStrings.Find(sTmp);
			
			if (nFound != -1)
			{
				lStrings.Delete(nFound);

				cout &lt;&lt; &quot;&gt; String \&quot;&quot; &lt;&lt; sTmp &lt;&lt; &quot;\&quot; found at position &quot; &lt;&lt; nFound+1 &lt;&lt; &quot; and removed.&quot; &lt;&lt; endl &lt;&lt; endl;
				
				cout &lt;&lt; &quot;&gt; Printing list...&quot; &lt;&lt; endl &lt;&lt; endl;

				if (!lStrings.Empty())
					cout &lt;&lt; lStrings;
				else
				{
					cout &lt;&lt; &quot;[Empty list]&quot; &lt;&lt; endl &lt;&lt; endl;
					break;
				}
			}
			else
				cout &lt;&lt; &quot;&gt; String \&quot;&quot; &lt;&lt; sTmp &lt;&lt; &quot;\&quot; not found.&quot; &lt;&lt; endl;
		}
		
		cout &lt;&lt; endl;
	} while (sTmp.Length());
	
	cout &lt;&lt; endl;
	//-----------------------------

	//-----------------------------
	cout &lt;&lt; &quot;&gt; Now getting a bit more complex... Let's create a list of lists of strings... An empty string finishes the list and an empty first string finishes the list of lists...&quot; &lt;&lt; endl &lt;&lt; endl;

	List&lt; List&lt;String&gt; &gt; lLists;
	List&lt;String&gt; lTmpList;
	int nStrings = 0;

	do
	{
		lTmpList.DeleteAll();
		
		cout &lt;&lt; &quot;&gt; Loading list &quot; &lt;&lt; lLists.Length()+1 &lt;&lt; &quot;...&quot; &lt;&lt; endl;
		
		do
		{
			cout &lt;&lt; &quot;\t&gt; String &quot; &lt;&lt; lTmpList.Length()+1 &lt;&lt; &quot;: &quot;;
			cin &gt;&gt; sTmp;
			
			if (sTmp.Length())
			{
				lTmpList.Add(sTmp);
				nStrings++;
			}
		} while (sTmp.Length());
		
		if (lTmpList.Length())
			lLists.Add(lTmpList);
	} while (lTmpList.Length());
	
	cout &lt;&lt; endl &lt;&lt; &quot;&gt; Entry finished. &quot; &lt;&lt; lLists.Length() &lt;&lt; &quot; list(s) loaded, &quot; &lt;&lt; nStrings &lt;&lt; &quot; string(s) loaded.&quot; &lt;&lt; endl &lt;&lt; endl &lt;&lt; endl;

	cout &lt;&lt; &quot;&gt; Printing lists (standard method)...&quot; &lt;&lt; endl &lt;&lt; endl;

	cout &lt;&lt; lLists;

	cout &lt;&lt; endl;
	
	cout &lt;&lt; &quot;&gt; Printing lists (custom method)...&quot; &lt;&lt; endl &lt;&lt; endl;
	
	for (int i = 0; i &lt; lLists.Length(); i++)
	{
		List&lt;String&gt; *plList = lLists.Elem(i);

		if (plList)
		{
			cout &lt;&lt; &quot;- List &quot; &lt;&lt; i &lt;&lt; endl &lt;&lt; endl;
			cout &lt;&lt; *plList;
			cout &lt;&lt; endl;
		}
	}
	//-----------------------------

    return 0;
}
</pre>
<p>Y esta su salida:</p>

<pre class="console">
List sample project
-------------------

> Creating a list of strings... An empty string finishes the list...

> String 1: Test 1
> String 2: Test 2
> String 3: Test 3, a little bit longer
> String 4:

> Entry finished. 3 string(s) loaded.

> Printing list...

Test 1
Test 2
Test 3, a little bit longer

> Type a string to find in the list (exact match) [empty = end]: Hello
> String "Hello" not found.

> Type a string to find in the list (exact match) [empty = end]: Test 1
> String "Test 1" found at position 1 and removed.

> Printing list...

Test 2
Test 3, a little bit longer

> Type a string to find in the list (exact match) [empty = end]: Test 1
> String "Test 1" not found.

> Type a string to find in the list (exact match) [empty = end]: test 2
> String "test 2" not found.

> Type a string to find in the list (exact match) [empty = end]: Test 2
> String "Test 2" found at position 1 and removed.

> Printing list...

Test 3, a little bit longer

> Type a string to find in the list (exact match) [empty = end]: Test 3, a little bit longer
> String "Test 3, a little bit longer" found at position 1 and removed.

> Printing list...

[Empty list]


> Now getting a bit more complex... Let's create a list of lists of strings... An empty string finishes the list and an empty first string finishes the list of lists...

> Loading list 1...
        > String 1: Test 1a
        > String 2: Test 1b
        > String 3: Test 1c
        > String 4:
> Loading list 2...
        > String 1: Test 2a
        > String 2: Test 2b
        > String 3: Test 2c
        > String 4: Test 2d
        > String 5:
> Loading list 3...
        > String 1: Test 3a
        > String 2: Test 3b
        > String 3: This is a looooooooooooooooooooooong string
        > String 4:
> Loading list 4...
        > String 1:

> Entry finished. 3 list(s) loaded, 10 string(s) loaded.


> Printing lists (standard method)...

Test 1a
Test 1b
Test 1c

Test 2a
Test 2b
Test 2c
Test 2d

Test 3a
Test 3b
This is a looooooooooooooooooooooong string


> Printing lists (custom method)...

- List 0

Test 1a
Test 1b
Test 1c

- List 1

Test 2a
Test 2b
Test 2c
Test 2d

- List 2

Test 3a
Test 3b
This is a looooooooooooooooooooooong string

</pre>
<p>Este proyecto también utiliza la <a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-string-class/">Clase String simple para C++</a> para mostrar a la clase List trabajando con clases personales. El mismo código podría utilizarse perfectamente reemplazando &#8220;String&#8221; por &#8220;string&#8221; e incluyendo los headers de la versión standard de <em>string</em>.</p>
<p>El código es completamente portable.</p>
<p>Ha sido desarrollado, compilado y testeado utilizando <a href="http://wxdsgn.sourceforge.net/">wxDev-C++</a> para Windows con el <a href="http://www.mingw.org/">compilador MinGW</a> (incluído en el paquete). En Linux, fue compilado utilizando el compilador GNU GCC.</p>
<p><a href="http://www.gnu.org/licenses/gpl-3.0.txt"><img src="http://www.neoegm.com/wp-content/uploads/2009/07/gplv3-127x511.png" alt="GNU GPL v3" title="GNU GPL v3" width="127" height="51" class="aligncenter size-full wp-image-251" /></a> <span class="aligncenter">String está liberado bajo la licencia <a href="http://www.gnu.org/licenses/gpl-3.0.txt">GNU GPL v3</a> (attached)&#8230;</span></p>
<p><br/><br />
También probé el proyecto para verificar la ausencia de fugas de memoria utilizando el <a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/">cppMemDbg – Librería fácil de usar de detección de fugas de memoria para C++</a> y no encontró ningún tipo de problema&#8230;</p>
<p>Podés descargar la salida de la librería y el proyecto adaptado para cppMemDbg aquí:</p>
<div align="center">
<p class="download"><a href="http://download.neoegm.com/software/list-class/List_Sample_Project_cppMemDbg_Output.txt">Descargar salida de cppMemDbg</a></p>
</div>
<div align="center">
<p class="download"><a href="http://download.neoegm.com/software/list-class/List_Sample_Project_1.0_cppMemDbg.zip">Descargar Proyecto Adaptado 1.0</a></p>
</div>
<p><br/><br />
Ahora, finalmente, los links de descarga:</p>
<div align="center">
<p class="download"><a href="http://download.neoegm.com/software/list-class/List_1.0.zip">Descargar Clase List 1.0</a></p>
</div>
<div align="center">
<p class="download"><a href="http://download.neoegm.com/software/list-class/List_Sample_Project_1.0.zip">Descargar Proyecto de Ejemplo 1.0</a></p>
</div>
<h4>Incoming search terms for the article:</h4>
<ul>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" title="c list class">c list class</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" title="list class c">list class c</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" title="class list c">class list c</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" title="lista simple c">lista simple c</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" title="clase lista c">clase lista c</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" title="LISTA SIMPLE EN C">LISTA SIMPLE EN C</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" title="listas simples en c">listas simples en c</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" title="clase lista en c">clase lista en c</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" title="c class list">c class list</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" title="list class in c">list class in c</a></li>
</ul>
<div class='yarpp-related-rss'>
<strong><p>Related posts:<ol>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-string-class/" rel="bookmark" title="Clase String simple para C++">Clase String simple para C++ </a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" rel="bookmark" title="cppMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C++">cppMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C++ </a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/control-de-asistencia/" rel="bookmark" title="Control de Asistencia">Control de Asistencia </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cppMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C++</title>
		<link>http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/</link>
		<comments>http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 11:51:13 +0000</pubDate>
		<dc:creator><![CDATA[NeoEGM]]></dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Download]]></category>
		<category><![CDATA[Easy]]></category>
		<category><![CDATA[Freeware]]></category>
		<category><![CDATA[GNU GPL]]></category>
		<category><![CDATA[Include]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[Memory Leaks]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Source Code]]></category>

		<guid isPermaLink="false">http://www.neoegm.com/?p=727</guid>
		<description><![CDATA[Esta librería es la secuela para C++ de cMemDbg. Tal como cMemDbg, es una librería muy fácil de usar que sirve para ayudar a detectar y trazar fugas de memoria (memory leaks). Su utilización es muy similar a la cMemDbg, pero con soporte para los operadores de C++ (new, new[], delete and delete[]). Hay muchas [&#8230;]<div class='yarpp-related-rss'>
<strong>
Related posts:<ol>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/" rel="bookmark" title="cMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C">cMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C </a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" rel="bookmark" title="Clase Lista simple para C++">Clase Lista simple para C++ </a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-string-class/" rel="bookmark" title="Clase String simple para C++">Clase String simple para C++ </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Esta librería es la secuela para C++ de <a href="http://www.neoegm.com/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/">cMemDbg</a>.</p>
<p>Tal como cMemDbg, es una librería muy fácil de usar que sirve para ayudar a detectar y trazar fugas de memoria (memory leaks).</p>
<p>Su utilización es muy similar a la cMemDbg, pero con soporte para los operadores de C++ (new, new[], delete and delete[]).</p>
<p>Hay muchas soluciones para esto en la red, pero esta tiene la particularidad de ser realmente simple de implementar.</p>

<pre class="console">>new  003D26D8  36  [Main.cpp:127]
>new  003D2708  36  [Main.cpp:128]
>ERROR  Bad free type  free => delete  003D2708  36
(Main.cpp:128)
>free  003D2708  36  (Main.cpp:128)  [Main.cpp:129]
>free  003D2708  0    [Main.cpp:130]
>ERROR  Trying to free unallocated memory: 003D2708
[Main.cpp:130]
>delete[]  003D3EB0  7  (String.cpp:59)  [String.h:41]
[...]
>delete[]  003D24F0  4  (String.cpp:59)  [String.h:41]
>delete  003D2490  40  (Lista.h:120)  [Lista.h:112]
>INFO  PROBLEM: Memory leak found (36 bytes)
>INFO  Unfreed block  003D26D8  36    [Main.cpp:127]
</pre>
<p><span id="more-727"></span>Simplemente hay que agregar el siguiente include al archivo principal de inclusión (un archivo que sea incluido por cada archivo del proyecto) o, en el caso de que no haya uno, a cada archivo que llame a una función de alocación de memoria (malloc, realloc, calloc, free, new, new[], delete or delete[]).</p>
<p>Esta es la línea:</p>
<pre class="brush: cpp; light: true; title: ; notranslate">#include &quot;cMemDbg.h&quot;</pre>
<p>Hay dos precauciones extra a tener en cuenta:<br />
1- Incluirlo <strong>después</strong> de los headers standard (stdio.h, stdlib.h, malloc.h, etc.).<br />
2- Nunca llamar al aperador delete (o delete[]) sin saber si su argumento es NULL. Así que &#8220;delete a;&#8221; debería pasar a ser &#8220;if (a) delete a;&#8221;. De otro modo, la librería puede mostrar mensajes incorrectos.</p>
<p>Eso es todo&#8230; Esperabas más? Bueno, hay un último paso&#8230; Tenés que hacer esta llamada justo antes de salir del programa para poder obtener las conclusiones detalladas:</p>
<pre class="brush: cpp; light: true; title: ; notranslate">PrintMemoryLeakInfo();</pre>
<p>Por defecto, la salida de la librería irá a stdout (normalmente la pantalla de la consola). Si querés redirigira a un archivo, podés llamar a la función InitCPPMemDbg(). Este es su prototipo:</p>
<pre class="brush: cpp; light: true; title: ; notranslate">void InitCPPMemDbg(const char *pszOutputPath = NULL);</pre>
<p>Otra opción, para simplificar, es crear un objeto global del tipo &#8220;cppMemDbg&#8221; al comienzo de las declaraciones globales. Podés pasarle una ruta de archivo al constructor para redirigir la salida. Este objeto se va a encargar de llamar automáticamente a InitCPPMemDbg  (para configurar la redirección) al construirse y a PrintMemoryLeakInfo al destruirse.</p>
<p>Así de simple:</p>
<pre class="brush: cpp; light: true; title: ; notranslate">cppMemDbg cDbg;</pre>
<p>O, con redirección:</p>
<pre class="brush: cpp; light: true; title: ; notranslate">cppMemDbg cDbg(&quot;mylocalfile.txt&quot;);</pre>
<p>Easy, not?</p>
<p>That was all&#8230; Really.</p>
<p>Fácil, no?</p>
<p>Eso fue todo&#8230; En serio.</p>
<p><a href="http://www.gnu.org/licenses/gpl-3.0.txt"><img src="http://www.neoegm.com/wp-content/uploads/2009/07/gplv3-127x511.png" alt="GNU GPL v3" title="GNU GPL v3" width="127" height="51" class="aligncenter size-full wp-image-251" /></a> <span class="aligncenter">cppMemDbg está liberado bajo la licencia <a href="http://www.gnu.org/licenses/gpl-3.0.txt">GNU GPL v3</a> (attached)&#8230;</span></p>
<p>Ahora, antes de ir a funcionalidades más &#8220;de experto&#8221;, voy a dejar el link para descargar la librería para aquellos que no quieran seguir leyendo:</p>
<div align="center">
<p class="download"><a href="http://download.neoegm.com/software/cppmemdbg/cppMemDbg_1.0.zip">Download</a></p>
</div>
<p>Ahora continuemos&#8230;</p>
<p>Esta librería viene con tres parámetros configurables (disponibles en cppMemDbg.cpp):</p>
<ul>
<li><strong>PRINT_OPERATIONS:</strong> Si está seteado en 1, se va a imprimir a la salida configurada (stdout por default) cada operación de alocación de memoria realizada en el programa (alocación o liberación). De otro modo, la librería sólo imprimirá problemas, notificaciones y el dump final. <em>[Valor predeterminado = 1]</em></li>
<li><strong>MAX_ALLOC:</strong> Largo del stack interno de memoria de la librería (en elementos). Es la máxima cantidad de alocaciones que pueden ser trazadas sin ser liberadas. Se puede incementar este valor a voluntad en casi de ser necesario. De hecho, si es necesario, la librería imprimirá un mensaje diciendo: &#8220;INTERNAL_ERROR: Allocation stack overflow, please increase MAX_ALLOC&#8221;. <em>[Valor predeterminado = 256]</em></li>
<li><strong>g_fFile:</strong> FILE* al cuál escribirle todas las notificaciones generadas por la librería. <em>[Valor predeterminado = stdout]</em></li>
<li><strong>MAX_DELETE_STACK:</strong> Largo del stack interno de <em>delete</em> de la librería (en elementos). Es la máxima cantidad de <em>delete</em>s que pueden anidarse. Se puede incementar este valor a voluntad en casi de ser necesario. De hecho, si es necesario, la librería imprimirá un mensaje diciendo: &#8220;INTERNAL_ERROR: Delete stack overflow, please increase MAX_DELETE_STACK&#8221;. <em>[Valor predeterminado = 16]</em></li>
</ul>
<p>Finalmente, hay dos funciones más que se pueden utilizar en caso de ser necesario:</p>
<ul>
<li><strong>PrintTotalAllocatedMemory():</strong> Imprime la cantidad acumulativa de memoria alocada al momento de la llamada.</li>
<li><strong>PrintMemoryReservedByCMemDbgLibrary():</strong> Imprime la cantidad de memoria reservada por la librería (definida en tiempo de compilación por la constante MAX_ALLOC).</li>
</ul>
<p>Eso es todo&#8230; Dije que era fácil de usar.</p>
<p>De todos modos si, luego de leer los comentarios del archivo cMemDbg.h, tenés algún tipo de pregunta, comentario o sugerencia, no dudes en contactarme.</p>
<p>Acá está el proyecto <a href="http://www.neoegm.com/es/tech/programming/c-cpp/control-de-asistencia/">Control de Asistencia</a> modificado para verificar la existencia de memory leaks y problemas de alocación/liberación de memoria con la librería cppMemDbg:</p>
<div align="center">
<p class="download"><a href="http://download.neoegm.com/software/cppmemdbg/ControlAsistencia_cppMemDbg.zip">Descargar proyecto de ejemplo</a></p>
</div>
<p>El código es portable entre Linux y Windows (lo testeé personalmente en ambas plataformas y funcionó idénticamente).</p>
<p>Ha sido desarrollado, compilado y testeado utilizando <a href="http://wxdsgn.sourceforge.net/">wxDev-C++</a> para Windows con el <a href="http://www.mingw.org/">compilador MinGW</a> (incluído en el paquete). En Linux, fue compilado utilizando el compilador GNU GCC.</p>
<p>Está configurado para enviar la salida al archivo &#8220;TestMemDbg.txt&#8221; del directorio actual. Esta es la parte importante del archivo Main.cpp:</p>
<pre class="brush: cpp; first-line: 101; highlight: [107,109]; title: ; notranslate">
//...

#include &quot;ControlDeAsistencia.h&quot;
#include &quot;BasicFunctions.h&quot;
#include &lt;fstream&gt;

#include &quot;cppMemDbg.h&quot;

cppMemDbg cDbg(&quot;TestMemDbg.txt&quot;);

//...
</pre>
<p>Y esta es su salida satisfactoria (la salida real está tabulada para hacer más simple su análisis utilizando un software de hoja de cálculos):</p>

<pre class="console">>new[]  003D3F58  14  [String.cpp:59]
>new[]  003D2438  14  [String.cpp:59]
>delete[]  003D3F58  14  (String.cpp:59)  [String.h:41]
>new[]  003D3EB0  7  [String.cpp:59]
>new[]  003D2450  7  [String.cpp:59]
[...]
>delete[]  003D2558  4  (String.cpp:59)  [String.h:41]
>delete[]  003D24F0  4  (String.cpp:59)  [String.h:41]
>delete  003D2490  40  (Lista.h:120)  [Lista.h:112]
>INFO  No memory leaks detected
</pre>
<h4>Incoming search terms for the article:</h4>
<ul>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" title="cppMemDbg">cppMemDbg</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" title="mingw memory leak detection">mingw memory leak detection</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" title="memory leak detection mingw">memory leak detection mingw</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" title="mingw memory leak">mingw memory leak</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" title="c memory leak library">c memory leak library</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" title="c memory leak detector">c memory leak detector</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" title="memory leak mingw">memory leak mingw</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" title="c memory leak detection library">c memory leak detection library</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" title="memory leak detection c">memory leak detection c</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" title="libreria para delete en c">libreria para delete en c</a></li>
</ul>
<div class='yarpp-related-rss'>
<strong><p>Related posts:<ol>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/" rel="bookmark" title="cMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C">cMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C </a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" rel="bookmark" title="Clase Lista simple para C++">Clase Lista simple para C++ </a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-string-class/" rel="bookmark" title="Clase String simple para C++">Clase String simple para C++ </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C</title>
		<link>http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/</link>
		<comments>http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 18:42:07 +0000</pubDate>
		<dc:creator><![CDATA[NeoEGM]]></dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Debug]]></category>
		<category><![CDATA[Easy]]></category>
		<category><![CDATA[Freeware]]></category>
		<category><![CDATA[GNU GPL]]></category>
		<category><![CDATA[Include]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[Memory Leaks]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Source Code]]></category>

		<guid isPermaLink="false">http://www.neoegm.com/?p=58</guid>
		<description><![CDATA[Después de algún tiempo de trabajar con C, decidí desarrollar una librería muy fácil de usar que pudiera ayudar a detectar y trazar fugas de memoria (memory leaks). Hay muchas soluciones para esto en la red, pero esta tiene la particularidad de ser realmente simple de implementar. Simplemente hay que agregar el siguiente include al [&#8230;]<div class='yarpp-related-rss'>
<strong>
Related posts:<ol>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" rel="bookmark" title="cppMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C++">cppMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C++ </a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" rel="bookmark" title="Clase Lista simple para C++">Clase Lista simple para C++ </a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-string-class/" rel="bookmark" title="Clase String simple para C++">Clase String simple para C++ </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Después de algún tiempo de trabajar con C, decidí desarrollar una librería muy fácil de usar que pudiera ayudar a detectar y trazar fugas de memoria (memory leaks).</p>
<p>Hay muchas soluciones para esto en la red, pero esta tiene la particularidad de ser realmente simple de implementar.</p>
<p><span id="more-58"></span><br />
Simplemente hay que agregar el siguiente include al archivo principal de inclusión (un archivo que sea incluido por cada archivo del proyecto) o, en el caso de que no haya uno, a cada archivo que llame a una función de alocación de memoria (malloc, realloc, calloc o free). La única precaución extra que hay que tener en cuenta es incluirlo <strong>después</strong> de los headers standard (stdio.h, stdlib.h, malloc.h, etc.).</p>
<p>Esta es la línea:</p>
<pre class="brush: plain; light: true; title: ; notranslate">#include &quot;cMemDbg.h&quot;</pre>
<p>Eso es todo&#8230; Esperabas más? Bueno, hay un último paso&#8230; Tenés que hacer esta llamada justo antes de salir del programa para poder obtener las conclusiones detalladas:</p>
<pre class="brush: plain; light: true; title: ; notranslate">PrintMemoryLeakInfo();</pre>
<p>Fácil, no?</p>
<p>Eso fue todo&#8230; En serio.</p>
<p>Ahora, antes de ir a funcionalidades más &#8220;de experto&#8221;, voy a dejar el link para descargar la librería para aquellos que no quieran seguir leyendo:</p>
<div align="center">
<p class="download"><a href="http://download.neoegm.com/software/cmemdbg/cMemDbg_1.0.zip">Descargar cMemDbg 1.0</a></p>
</div>
<p>Ahora continuemos&#8230;</p>
<p>Esta librería viene con tres parámetros configurables (disponibles en cMemDbg.c):</p>
<ul>
<li><strong>PRINT_OPERATIONS:</strong> Si está seteado en 1, se va a imprimir a la salida configurada (stdout por default) cada operación de alocación de memoria realizada en el programa (alocación o liberación). De otro modo, la librería sólo imprimirá problemas, notificaciones y el dump final. <em>[Valor predeterminado = 1]</em></li>
<li><strong>MAX_ALLOC:</strong> Largo del stack interno de memoria de la librería (en elementos). Es la máxima cantidad de alocaciones que pueden ser trazadas sin ser liberadas. Se puede incementar este valor a voluntad en casi de ser necesario. De hecho, si es necesario, la librería imprimirá un mensaje diciendo: &#8220;INTERNAL_ERROR: Allocation stack overflow, please increase MAX_ALLOC&#8221;. <em>[Valor predeterminado = 256]</em></li>
<li><strong>PRINT_OUTPUT:</strong> Destino de impresión de las notificaciones generadas por la librería (puede ser cualquier stream/archivo en el que se pueda imprimir utilizando fprintf). <em>[Valor predeterminado = stdout]</em></li>
</ul>
<p>Finalmente, hay dos funciones más que se pueden utilizar en caso de ser necesario:</p>
<ul>
<li><strong>PrintTotalAllocatedMemory():</strong> Imprime la cantidad acumulativa de memoria alocada al momento de la llamada.</li>
<li><strong>PrintMemoryReservedByCMemDbgLibrary():</strong> Imprime la cantidad de memoria reservada por la librería (definida en tiempo de compilación por la constante MAX_ALLOC).</li>
</ul>
<p>Eso es todo&#8230; Dije que era fácil de usar.</p>
<p>De todos modos si, luego de leer los comentarios del archivo cMemDbg.h, tenés algún tipo de pregunta, comentario o sugerencia, no dudes en contactarme.<br />
<h4>Incoming search terms for the article:</h4>
<ul>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/" title="detectar fugas de memoria en c">detectar fugas de memoria en c</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/" title="cmemdbg">cmemdbg</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/" title="c memory leak">c memory leak</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/" title="detectar fuga memoria c">detectar fuga memoria c</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/" title="detectar fugas de memoria">detectar fugas de memoria</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/" title="internal_error allocation stack overflow please increase max_alloc">internal_error allocation stack overflow please increase max_alloc</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/" title="detectar memory leaks c">detectar memory leaks c</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/" title="detectar fugas de memoria c">detectar fugas de memoria c</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/" title="freebsd memory leak detection">freebsd memory leak detection</a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/" title="Detector de fugas de memoria">Detector de fugas de memoria</a></li>
</ul>
<div class='yarpp-related-rss'>
<strong><p>Related posts:<ol>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/cppmemdbg-easy-to-use-cpp-memory-leak-detection-library/" rel="bookmark" title="cppMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C++">cppMemDbg &#8211; Librería fácil de usar de detección de fugas de memoria para C++ </a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-list-class/" rel="bookmark" title="Clase Lista simple para C++">Clase Lista simple para C++ </a></li>
<li><a href="http://www.neoegm.com/es/tech/programming/c-cpp/simple-string-class/" rel="bookmark" title="Clase String simple para C++">Clase String simple para C++ </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.neoegm.com/es/tech/programming/c-cpp/cmemdbg-easy-to-use-c-memory-leak-detection-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
