<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>How much memory does this use?</title>
		<link>http://www.allegro.cc/forums/view/609471</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 04 Feb 2012 10:06:22 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is a really simple question which is actually obvious although I&#39;m not sure if it its wrong on my behalf so here is the code. I left comments related to the question.</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#include &lt;vector&gt;</span>

<span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span>
<span class="k2">{</span>
  <span class="k1">int</span> memory1 <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span><span class="c">//does memory1 use more memory than memory2</span>
  std::vector<span class="k3">&lt;</span>int&gt; memory2<span class="k2">;</span><span class="c">//does this use any memory at all?</span>

  <span class="c">//now are they the same? or is memory 2 larger in size?</span>
  memory2.push_back<span class="k2">(</span><span class="n">0</span><span class="k2">)</span><span class="k2">;</span>

  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Sat, 04 Feb 2012 09:36:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Use <span class="source-code"><span class="k1">sizeof</span></span> to see. Of course it won&#39;t tell you the full memory of the vector, but it should be enough to convince you that even an empty vector has overhead.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 04 Feb 2012 09:41:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So an empty vector does have overhead, thats what I was wondering.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Sat, 04 Feb 2012 09:46:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>By the way, is there a programmatically easy and direct way to find out the total amount of memory that an Allegro program is using?</p><p>Or we can only resort to sizeof every instantiation?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bernardo Lopes)</author>
		<pubDate>Sat, 04 Feb 2012 09:51:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You could also try using Process Explorer on your machine as long as its windows I think. I have XP. It gives a lot of info about the program running in memory.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Sat, 04 Feb 2012 09:52:55 +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/609471/946572#target">Bernardo Lopes</a> said:</div><div class="quote"><p> Or we can only resort to sizeof every instantiation?
</p></div></div><p>That tells you the size of the data type, which is fixed at compile time.</p><p>If you want to know how much memory Allegro is using from <span class="source-code"><a href="http://www.allegro.cc/manual/al_malloc"><span class="a">al_malloc</span></a><span class="k2">(</span><span class="k2">)</span></span> calls, set a custom memory interface and track the bytes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 04 Feb 2012 09:56:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, at the very least I&#39;d assume the vector has to store <span class="source-code"><span class="k1">int</span><span class="k3">*</span></span> and <span class="source-code"><span class="k1">size_t</span></span>. So it would take more memory than the plain <span class="source-code"><span class="k1">int</span></span> regardless of whether or not it is empty. Also, the vector typically allocates more memory than is strictly required. You can see how much memory it has allocated for data by using <a href="http://www.cplusplus.com/reference/stl/vector/capacity/">std::vector::capacity</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Karadoc ~~)</author>
		<pubDate>Sat, 04 Feb 2012 10:06:22 +0000</pubDate>
	</item>
</rss>
