Note that there are some explanatory texts on larger screens.

plurals
  1. POMeasuring total space function allocates on heap and stack during it's entire lifetime
    primarykey
    data
    text
    <p>I have a recursive function written in C++ that dynamically allocates 2D arrays using <code>new</code>. How could I measure the total amount space function allocates on heap and stack during it's entire lifetime ?</p> <p>Here is an example(it is not my code) of how to measure Stack.</p> <pre><code>unsigned int maxStackLocation ; unsigned int minStackLocation ; main () { //get the address of a local variable before calling Quicksort //the stack grows down, so this is the max stack location int localVariable; void *currPtrLocation = (void*)(&amp;localVariable); maxStackLocation = *(unsigned int *)(&amp;currPtrLocation); //we get the value for the minimum stack location in quicksort itself //call quicksort Quick (A, num); space = maxStackLocation - minStackLocation; } //some redundant function whose stack usage will be measured void Quick (unsigned int A[], int num) { if (num &lt;= 1) { //check the stack usage //figure out where we are on the stack by looking at the byte // address of the local variable //we do this by making a pointer to a local variable, and then //casting it to a integer void *currPtrLocation = (void*)(&amp;num); unsigned int currStackLocation = *(unsigned int*)(&amp;currPtrLocation); if (currStackLocation &lt; minStackLocation) minStackLocation = currStackLocation; return; } } </code></pre> <p><strong>Edit</strong><br> Borgleader points out that my original question "Measuring max space function allocates on heap and stack during it's entire lifetime" is incorrect. I have changed "max" to "total".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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