<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5]use custom memory allocator in allegro carefully</title>
		<link>http://www.allegro.cc/forums/view/614745</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 29 Oct 2014 19:45:06 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>if you use custom memory allocator to replace allegro&#39;s default allocator,plz be careful.</p><p>before use the method al_set_memory_interface(), allegro use default allocator to malloc/free.So you need al_set_memory_interface before allegro install.</p><p>Even if you do so, or have an opportunity to cause a memory leak. like this:<br />class String is a wrapper of allegro&#39;s string methods. Define a local variables in a cpp file.</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 1</span><span class="p">#include &lt;xxx.h&gt;</span>
<span class="number"> 2</span>
<span class="number"> 3</span>String str<span class="k2">(</span><span class="s">"test"</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p>

this string&#39;s memory is malloc before the main(), use the default malloc. so you must use default  free() to free it.  that mean you need use al_set_memory_interface() again, after allegro uninstall, to replace your custom allocator with default.</p><p>so ,don&#39;t use al_init(), that method will automatic call al_uninstall_system after main(). <br />you need do like this:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>    <a href="http://www.allegro.cc/manual/al_set_memory_interface"><span class="a">al_set_memory_interface</span></a><span class="k2">(</span><span class="k3">&amp;</span>yourallocator<span class="k2">)</span><span class="k2">;</span>
<span class="number">  4</span>    <a href="http://www.allegro.cc/manual/al_install_system"><span class="a">al_install_system</span></a><span class="k2">(</span>ALLEGRO_VERSION_INT, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span>
<span class="number">  6</span>    ...your game codes
<span class="number">  7</span>
<span class="number">  8</span>    <a href="http://www.allegro.cc/manual/al_uninstall_system"><span class="a">al_uninstall_system</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>    <a href="http://www.allegro.cc/manual/al_set_memory_interface"><span class="a">al_set_memory_interface</span></a><span class="k2">(</span><span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span><span class="k2">}</span>
</div></div><p>
hope help you.;D
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (vkensou)</author>
		<pubDate>Fri, 24 Oct 2014 19:07:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Those are some good points <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>We should probably include them in the documentation, assuming they aren&#39;t already.</p><p>That point about the statically allocated object is a very good one, as it can affect more than just memory management. If you try to call allegro API functions in that object&#39;s constructor, things can go horribly wrong.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 24 Oct 2014 19:17:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
thank you for your reply. hope it could help someone else
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (vkensou)</author>
		<pubDate>Mon, 27 Oct 2014 12:37:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Good points.  Thank you for bringing them up.</p><p>What&#39;s the easiest way to make such a doc contribution from a web browser?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Gideon Weems)</author>
		<pubDate>Tue, 28 Oct 2014 17:20:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Send a patch to the mailing list (via webmail) or attach to a post on the Allegro Developement forum subsection.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 28 Oct 2014 17:38:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can also edit the documentation online at <a href="https://github.com/liballeg/allegro5/blob/5.1/docs/src/refman/memory.txt">https://github.com/liballeg/allegro5/blob/5.1/docs/src/refman/memory.txt</a> <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> (And then submit with &quot;Pull Request&quot;.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 29 Oct 2014 19:45:06 +0000</pubDate>
	</item>
</rss>
