<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Memory usage too high? [A5]</title>
		<link>http://www.allegro.cc/forums/view/608651</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 25 Oct 2011 23:49:28 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am developing an adventure game. It has much scenery art 800*600 png files and sprite sheets of 1200*1024. Task manager shows memory usage of 208MB currently and it starts to concern me. I guess when all the png images are held in video RAM as bitmaps then it obviously occupies so much memory but what could I do to optimize this and how high should be the maximum memory usage for such an artistic game? I mean most games take much memory nowadays but how much is too much for a 2.5D adventure game? It is a room based game so that when you move to next room it could be possible to quickly load new graphics from disk and destroy old. In that case I hope it won&#39;t use too much time to load from later planned zip virtual FS.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Hyena_)</author>
		<pubDate>Sun, 23 Oct 2011 15:53:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Only load the pngs that are needed for the current scene.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Sun, 23 Oct 2011 19:03:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you&#39;re storing the uncompressed bitmaps in memory, it may be a reasonable compromise to store the compressed PNG data in memory instead.  They can be decompressed into memory as needed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (raynebc)</author>
		<pubDate>Sun, 23 Oct 2011 21:28:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In that case, how to load a png image from memory? How to load a file into memory as it is in the first place and later on how to convert a png in RAM into bitmap in VRAM?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Hyena_)</author>
		<pubDate>Sun, 23 Oct 2011 23:21:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This will give you the general idea.  Add error checking, and please don&#39;t try to compile this code as-is. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p><div class="source-code snippet"><div class="inner"><pre>    <span class="c">/* read image file into memory */</span>
    <a href="http://www.allegro.cc/manual/ALLEGRO_FILE"><span class="a">ALLEGRO_FILE</span></a><span class="k3">*</span> file <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_fopen"><span class="a">al_fopen</span></a><span class="k2">(</span><span class="s">"file.png"</span>, <span class="s">"r"</span><span class="k2">)</span><span class="k2">;</span>
    <span class="k1">int64_t</span> size <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_fsize"><span class="a">al_fsize</span></a><span class="k2">(</span>file<span class="k2">)</span><span class="k2">;</span>
    <span class="k1">void</span><span class="k3">*</span> buffer <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_malloc"><span class="a">al_malloc</span></a><span class="k2">(</span>cast<span class="k2">(</span><span class="k1">size_t</span><span class="k2">)</span>size<span class="k2">)</span><span class="k2">;</span>
    <a href="http://www.allegro.cc/manual/al_fread"><span class="a">al_fread</span></a><span class="k2">(</span>file, buffer, size<span class="k2">)</span><span class="k2">;</span>
    <a href="http://www.allegro.cc/manual/al_fclose"><span class="a">al_fclose</span></a><span class="k2">(</span>file<span class="k2">)</span><span class="k2">;</span>

   <span class="c">/* create bitmap from memory */</span>
   <a href="http://www.allegro.cc/manual/ALLEGRO_FILE"><span class="a">ALLEGRO_FILE</span></a> <span class="k3">*</span>memfile <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_open_memfile"><span class="a">al_open_memfile</span></a><span class="k2">(</span>buffer, size, <span class="s">"r"</span><span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span><a href="http://www.allegro.cc/manual/al_load_bitmap_f"><span class="a">al_load_bitmap_f</span></a><span class="k2">(</span>memfile, <span class="s">".png"</span><span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/al_fclose"><span class="a">al_fclose</span></a><span class="k2">(</span>memfile<span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/al_free"><span class="a">al_free</span></a><span class="k2">(</span>buffer<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
<a href="http://alleg.sourceforge.net/a5docs/refman/memfile.html">http://alleg.sourceforge.net/a5docs/refman/memfile.html</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Mon, 24 Oct 2011 00:31:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Do seek operations work properly on memory buffered files?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (raynebc)</author>
		<pubDate>Tue, 25 Oct 2011 02:33:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608651/935172#target">raynebc</a> said:</div><div class="quote"><p>Do seek operations work properly on memory buffered files?</p></div></div><p>To the degree that you can seek inside the buffer sure. Trying to seek outside, or write/read outside the buffer will cause functions to return errors.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 25 Oct 2011 04:22:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s good, I just wanted to make sure it would properly return EOF if the end of the buffered file was reached.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (raynebc)</author>
		<pubDate>Tue, 25 Oct 2011 21:52:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608651/935068#target">torhu</a> said:</div><div class="quote"><p>This will give you the general idea.</p></div></div><p>What&#39;s wrong with loading the bitmap as a memory bitmap then transferring to video as required instead of loading into a memory block using the code shown?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Tue, 25 Oct 2011 22:07:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>He wouldn&#39;t save any system RAM that way...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Tue, 25 Oct 2011 23:49:28 +0000</pubDate>
	</item>
</rss>
