Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code> unsigned int buffsize = 100000000; unsigned long long counter = 0;</p> <pre><code>try { vector&lt;shared_ptr&lt;char*&gt;&gt; pool; // container to hold the allocated memory, shared pointer does clean up for us. while(true) { shared_ptr&lt;char*&gt; sp = make_shared&lt;char*&gt;(new char[buffsize]); // allocate memory, //this can potentially leak memory if compiled with msvc version &lt; 10 sp1. pool.push_back(sp); // insert into vector counter += (sizeof(char) * buffsize); // increment counter , counter will be size in bytes } } catch(std::bad_alloc a) // capture exception by value, as to not leak the exception { cout &lt;&lt; "Approximate size of heap: \r\n" &lt;&lt; counter &lt;&lt; " Bytes" &lt;&lt; endl; // output counter's size. cout &lt;&lt; counter/1024 &lt;&lt; " KiloBytes" &lt;&lt; endl; cout &lt;&lt; (counter/1024)/1024 &lt;&lt; " MegaBytes" &lt;&lt; endl; cout &lt;&lt; (((counter)/1024)/1024)/1024 &lt;&lt; " GigaBytes" &lt;&lt; endl; cin.get(); } </code></pre> <p></code></p> <p>Compile with Visual Studio 10 or better, the latest GCC should be a safe option as well. For the question dealing with signed / unsigned <a href="http://www.cplusplus.com/forum/general/33691/" rel="nofollow" title="go here"> go here</a>, And for an explanation on built in data types <a href="http://www.cplusplus.com/doc/tutorial/variables/" rel="nofollow">go here</a>. the long identifier is used to increase the storage of the data type, such as the difference between a double and a long double. A long long on my system/platform for instance is 8 bytes, where as a regular long is 4 bytes. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload