<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Dec 27, 2013 at 12:21 AM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@gmail.com" target="_blank">chandlerc@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="im"><br><div class="gmail_quote">On Thu, Dec 26, 2013 at 2:29 PM, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com" target="_blank">kcc@google.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div> >> Isn't clang multithreaded? What about synchronization?<br>


</div>  no (afaict)<br>
  If it ever becomes multithreaded, we can guard the push_backs by a mutex (will add a tiny bit of ugliness)</blockquote></div><div class="gmail_extra"><br></div></div>I think we could probably do a lot cheaper than a vector at least for the common case -- we know we will *never* need to traverse this, and it will probably be relatively small (at least, I hope...).<br>

</div><div class="gmail_extra"><br></div><div class="gmail_extra">I would compile some big single source files (single-source gcc, some super big C++ code, etc.) with a hack that prints out how many free() calls are being omitted via this flag. If the number is O(10000) I would probably do something kinda horrible:</div>
</div></blockquote><div>I expect it to be more like ~10 than ~10000. Remember we don't need to store all leaked heap objects there, only the roots.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div class="gmail_extra"><br></div><div class="gmail_extra">"""</div><div class="gmail_extra">static const unsigned NumPointersPerGraveYard = ((1 << 16) / sizeof(void*)) - 1;<br></div></div></blockquote>
<div><br></div><div>But this is so much more code than a single vector!? </div><div>(And I like the naming!)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra"></div><div class="gmail_extra">
static unsigned GraveYardIndex = 0;</div><div class="gmail_extra">struct PointerGraveYard {</div><div class="gmail_extra">  void *DeadPtrs[NumPointersPerGraveYard];</div><div class="gmail_extra">  PointerGraveYard *PrevGraveYard;</div>

<div class="gmail_extra">} InitialGraveYard, *CurrentGraveYard = &InitialGraveYard;</div><div class="gmail_extra"><br></div><div class="gmail_extra">void BuryPointer(void *p) {</div><div class="gmail_extra">  PointerGraveYard *G = CurrentGraveYard;</div>

<div class="gmail_extra">  if (GraveYardIndex >= NumPointersPerGraveYard) {</div><div class="gmail_extra">    CurrentGraveYard = new PointerGraveYard;</div><div class="gmail_extra">    CurrentGraveYard->PrevGraveYard = G;</div>

<div class="gmail_extra">    G = CurrentGraveYard;</div><div class="gmail_extra">    GraveYardIndex = 0;</div><div class="gmail_extra">  }</div><div class="gmail_extra"><br></div><div class="gmail_extra">  G->DeadPtrs[GraveYardIndex++] = p;</div>

<div class="gmail_extra">}</div><div class="gmail_extra">"""</div><div class="gmail_extra"><br></div><div class="gmail_extra">This seems likely to be way cheaper than the vector in all of the common cases. I'm not really worried about the size of the static global either because it would be mapped by the loader rather than taking up actual data size in the binary.</div>
<span class="HOEnZb"><font color="#888888">
<div class="gmail_extra"><br></div><div class="gmail_extra">-Chandler</div></font></span></div>
</blockquote></div><br></div></div>