<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5] How to optimize al_draw_textf</title>
		<link>http://www.allegro.cc/forums/view/617916</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 05 Sep 2019 04:23:18 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi, I&#39;m trying to optimize my Snake game so it uses less and less of RAM and I came to the conclusion that al_draw_textf() function uses the most memory in my case. I&#39;m using this function to draw score on the screen every frame and just wanted to know if is there any way to optimize that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wixy00)</author>
		<pubDate>Wed, 04 Sep 2019 08:09:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Use smaller text font? Or less glyphs? <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Wed, 04 Sep 2019 14:29:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you saying you&#39;ve profiled your game&#39;s memory usage and found that <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_textf"><span class="a">al_draw_textf</span></a></span> is allocating large amounts of memory? Or is it your usage of the fonts addon in general (allocating <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a></span>s et al)?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dthompson)</author>
		<pubDate>Wed, 04 Sep 2019 16:11:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve profiled memory usage using VS 2017.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wixy00)</author>
		<pubDate>Wed, 04 Sep 2019 19:40:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Give me your source code and resources and I&#39;ll verify your claim and investigate.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 04 Sep 2019 20:07:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m sorry I&#39;m new here. How can I send you my code and resources?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wixy00)</author>
		<pubDate>Wed, 04 Sep 2019 20:23:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>wixy00, welcome to allegro.cc.</p><p>When you reply to this post, add a zip file of your source and resources using the Drop Attachments here button.</p><p>You can then link to them using an href tag.</p><p>Allegro.cc uses XHTML tags, like &lt;code&gt;code goes here...&lt;/code&gt; and &lt;a href=&quot;URL&quot;&gt;Link name&lt;/a&gt; so. Images are similar - &lt;img src=&quot;<a href="https://www.allegro.cc/files/attachment/612136">https://www.allegro.cc/files/attachment/612136</a>&quot; /&gt; yields :</p><p><span class="remote-thumbnail"><span class="json">{"name":"612136","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/f\/5f3f6e41c7c17d71258fffdae7417326.png","w":1210,"h":907,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/f\/5f3f6e41c7c17d71258fffdae7417326"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/5/f/5f3f6e41c7c17d71258fffdae7417326-240.jpg" alt="612136" width="240" height="179" /></span></p><p>Right click on the attachment and copy the link location. Then paste it in your post.</p><p><a href="https://www.allegro.cc/files/attachment/612136">https://www.allegro.cc/files/attachment/612136</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 04 Sep 2019 20:43:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you, good to know.</p><p><a href="https://www.allegro.cc/files/attachment/612137">Snake.rar</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wixy00)</author>
		<pubDate>Wed, 04 Sep 2019 20:52:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve managed to build and successfully run your game.</p><p>I profiled the memory usage, and I don&#39;t see anything unusual. I see two large sets of allocation, one on startup, and one on entering the game.</p><p>I&#39;ll admit I&#39;ve never used the VS profiler before, so.... how did you come to your conclusion that al_draw_textf was using too much memory? Please tell me the steps I can take to reproduce this.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 04 Sep 2019 21:39:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s actually not that this function uses too much memory, it&#39;s using more than for example drawing bitmap. I wanted to know if there is any way to optimize that. I tried drawing regions of digits.png and it seems to be working just fine but it requires too much work to prepare (I mean in graphics program). If you want you can comment out current version of main game loop located in Run() and use the other one to check memory usage.</p><p><span class="remote-thumbnail"><span class="json">{"name":"612138","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/2\/72118338fdd91d49b5de3e60985a550b.png","w":749,"h":183,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/2\/72118338fdd91d49b5de3e60985a550b"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/7/2/72118338fdd91d49b5de3e60985a550b-240.jpg" alt="612138" width="240" height="58" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wixy00)</author>
		<pubDate>Wed, 04 Sep 2019 21:51:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, that sounds about right. You&#39;re essentially paying for <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_textf"><span class="a">al_draw_textf</span></a></span>&#39;s versatility here with a <b>tiny, tiny</b> bit more runtime memory than with a custom solution with <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_bitmap_region"><span class="a">al_draw_bitmap_region</span></a></span>. If you want to optimise the heck out of your game, go ahead and create that (more specialised) solution.</p><p>However - and sorry to be that guy - I think it&#39;s worth asking whether the optimisation is worth your time. Unless you&#39;re rendering thousands of formatted strings of text, I&#39;d be very happy with that memory usage; it may drop even further if you&#39;re using the non-debug DLLs.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dthompson)</author>
		<pubDate>Thu, 05 Sep 2019 03:16:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The reason al_draw_textf is allocating memory is because the glyphs haven&#39;t been cached yet. Allegro 5 caches glyphs on demand.</p><p>I&#39;ll second dthompson here, and say that this is really a non-issue. Unless you want to spend your time optimizing allegro instead of your own code, there&#39;s really no point in worrying about it. There&#39;s no memory leak.</p><p>You might reduce memory usage by disabling memory bitmap backups. This only applies on Windows with D3D but you can disable bitmap backups using the following code :</p><div class="source-code snippet"><div class="inner"><pre><span class="c">/// create display</span>

<a href="http://www.allegro.cc/manual/al_set_new_bitmap_flags"><span class="a">al_set_new_bitmap_flags</span></a><span class="k2">(</span>ALLEGRO_VIDEO_BITMAP <span class="k3">|</span> ALLEGRO_NO_PRESERVE_TEXTURE<span class="k2">)</span><span class="k2">;</span>

<span class="c">/// Now create the font, which respects the new bitmap flags</span>
<a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a><span class="k3">*</span> <a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font"><span class="a">al_load_ttf_font</span></a><span class="k2">(</span>...<span class="k2">)</span><span class="k2">;</span>

<span class="c">/// Now precache ONLY the glyphs that we want</span>
<a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span><span class="s">"0123456789"</span> , ...<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 05 Sep 2019 03:27:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I know there is no point optimizing such a simple game, but now I have a lot of free time so it was rather for learning purposes. Anyway, thank you for your time, I&#39;m glad that finally someone is willing to help me.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wixy00)</author>
		<pubDate>Thu, 05 Sep 2019 04:23:18 +0000</pubDate>
	</item>
</rss>
