title: Get unique id based on stack trace. Fast
body: <p>This question based on <a href="https://stackoverflow.com/questions/41415497/very-slow-stack-frames-in-static-library">Very slow stack frames in static library</a> .</p>
  
  <p>How get unique identify for this stack trace? It need for my memory manager: <a href="https://github.com/mikelsv/memman" rel="nofollow noreferrer">https://github.com/mikelsv/memman</a>.</p>
  
  <p>The problem with the interception of calls from the openssl library (and perhaps others libraries).</p>
  
  <p><strong>Problems:</strong></p>
  
  <ol>
  <li>Get unique id for prevous stack frame. Need for: <code>Type *tel = FindType(prevous stack name); tel-&gt;allocate count ++;</code></li>
  <li>Get unique id for all stack frames. Need for: <code>Stack *sel = FindStack(uniq stack id); sel-&gt;allocate count ++;</code></li>
  </ol>
  
  <p><strong>The current solution:</strong></p>
  
  <p>Use <code>CaptureStackBackTrace()</code> else <code>StackWalk()</code>. But, <code>CaptureStackBackTrace()</code> - don't show all stack frames, <code>StackWalk()</code> - very slowly.</p>
  
  <p>How do I get faster unique identifier stack?</p>
  
  <p><strong>Current code:</strong> <a href="https://github.com/mikelsv/msvcore2/blob/master/define/memcon.h" rel="nofollow noreferrer">https://github.com/mikelsv/msvcore2/blob/master/define/memcon.h</a></p>
  
  <ol>
  <li>See <code>GetStackTypeInfo();</code></li>
  <li>See <code>StackCrc();</code> - fast, but count short stack. Example: First stack frame <code>CRYPTO_realloc</code>. This problem: only one unique id for <code>"any calls" -&gt; CRYPTO_realloc()</code>.</li>
  </ol>
  
  <p><strong>Possible solutions:</strong></p>
  
  <ol>
  <li>Can i get unique id for stack frames use <code>RtlCaptureContext()</code>?</li>
  <li><p>What about use ebp?</p>
  
  <pre><code>unsigned long prev;
  unsigned long addr = 1;
  int eframes = 0;
  
  __asm { mov prev, ebp };
  
  while(addr != 0){
      addr = ((unsigned long *)prev)[1]; 
      prev = ((unsigned long *)prev)[0]; 
      stack[eframes] = (void*)addr;
      eframes ++;
  }
  </code></pre></li>
  </ol>
  
  <p>Here the problem when: CRYPTO_function_name() call my malloc(). In process addr == 32768, prev == 2; Exception in next loop. Result as CaptureStackBackTrace(). How to get the previous stack frames?</p>
  
  <ol start="3">
  <li>Other quick solutions?</li>
  </ol>