<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>can anyone help tell me why i run out of memory?</title>
		<link>http://www.allegro.cc/forums/view/591073</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 19 Apr 2007 20:34:50 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>hi There,</p><p> I&#39;ve been trying to get better at programming by way of writing some functions for handling numbers bigger than unsigned ints. I wanted to do this for various purposes - factorising large composite numbers and also for a search for an odd perfect number ( <a href="http://www.oddperfect.org/">http://www.oddperfect.org/</a> ). My program works well but I always get OUT OF MEMORY errors when doing large searches. It&#39;s not strictly allegro related but I was wondering if anyone would be willing to take a look at my code to see if they could tell why this is happening ?</p><p>thanks
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Thu, 19 Apr 2007 01:52:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you posted relevant code, it would help you get better responses.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Thu, 19 Apr 2007 02:06:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>First, completely baseless guess: you&#39;re allocating too much on the stack.</p><p>Show code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Thu, 19 Apr 2007 02:08:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What a lame plug.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Thu, 19 Apr 2007 02:08:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Okay thanks for the willingness to help.</p><p>P and N are #defines<br />The program basically chooses every combination of P dinstinct primes from a ordered list of N primes and then works out 1. The product. (easyily done) and then 2. The sum of all the products divisors and then plot the results on a loglog<br />graph.<br />BTW I know an odd perfect number can&#39;t be square free but I&#39;m still interested in these numbers (products of dinstinst primes) and besides I&#39;m just testing my program for more relevant searching later.</p><p>I&#39;ve got two questions I&#39;d really love to have answered :-</p><p>1. Why it runs out of memory.</p><p>You have to change N in action.c to about 3000 to see this.</p><p>2. Why the lines</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_Z<span class="k2">]</span><span class="k2">)</span>
            <a href="http://www.allegro.cc/manual/save_bitmap" target="_blank"><span class="a">save_bitmap</span></a><span class="k2">(</span><span class="s">"graph.bmp"</span>, graph, palette<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

 don&#39;t work. I need this ATM because I can then save the results before the program crashes or if I only want to run it a certain distance.</p><p>Also, If you want to see what the program&#39;s doing, change WATCH_RESULTS to 1.</p><p>Hoping for help, Will
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Thu, 19 Apr 2007 02:56:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>And first prize goes to... me!<br />Allocate your arrays dynamically and you&#39;ll stop running out of memory.</p><p>[EDIT]<br />As for point 2, I grepped for save_bitmap in your code and found this:
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
</p><div class="source-code snippet"><div class="inner"><pre>      <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/keypressed" target="_blank"><span class="a">keypressed</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
            <a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>

         <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_Z<span class="k2">]</span><span class="k2">)</span>
            <a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>

         <span class="k1">if</span><span class="k2">(</span>number_of_composites % <span class="n">10000</span> <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span> <span class="k2">{</span>
            <a href="http://www.allegro.cc/manual/save_bitmap" target="_blank"><span class="a">save_bitmap</span></a><span class="k2">(</span><span class="s">"graph.bmp"</span>, graph, palette<span class="k2">)</span><span class="k2">;</span>
      
         <span class="k2">}</span>
</pre></div></div><p>
</p></div></div><p>
Do think about what happens when a key is pressed, and you&#39;ll see why your <tt>if(key[KEY_Z])</tt> never gets executed. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Thu, 19 Apr 2007 03:00:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>yeh but the keypressed() function never works even when a key is pressed (exit(1))<br />isn&#39;t called.<br />None of the keyboard routines work in that file.</p><p>About the dynamic allocation : I thought automatic variables come and go with function calls. Am I missing something ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Thu, 19 Apr 2007 03:07:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Did install_keyboard fail when you called it?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Thu, 19 Apr 2007 03:28:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, I just checked for that but it calls OK.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Thu, 19 Apr 2007 03:37:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>what OS/compiler are you using?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michael Jensen)</author>
		<pubDate>Thu, 19 Apr 2007 09:17:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Using Windows XP with gcc v 2.95.3-6 (mingw special).<br />Perhaps the compiler&#39;s too old but it&#39;s the one I&#39;ve always used with allegro 4.0
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Thu, 19 Apr 2007 17:46:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, it might help if you would upgrade to  at least GCC 4 and Allegro 4.2 series, they are both around 5 or more years newer than the ones you are using <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (HoHo)</author>
		<pubDate>Thu, 19 Apr 2007 17:50:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, GCC 3.4 at least. There&#39;s no official GCC 4 for MinGW.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Thu, 19 Apr 2007 20:34:50 +0000</pubDate>
	</item>
</rss>
