<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">FWIW, the way Small* works is it allocates some initial number of elements directly inside the object, which means if it's stack-based, the entire object might live on the stack.</div>
</blockquote><div><br></div><div>I'd figured as much - which is why I was a bit surprised to see SmallVectorImpl's ctor taking the size at runtime...<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
// Entirely stack-based until you grow past 32 elements.<br>
SmallVector<E, 32> X<br>
// Minimum stack size, initial 32-element heap allocation<br>
SmallVectorImpl<E> X(32);<br></blockquote><div><br></div><div>I /think/ that isn't the case. Line 68 of <a href="http://llvm.org/docs/doxygen/html/SmallVector_8h_source.html">SmallVector.h</a> contains SmallVector's ctor and it has: <br>
<br>"<span class="Apple-style-span" style="font-family: Fixed, monospace; font-size: 13px; white-space: pre; background-color: rgb(245, 245, 245); "><a class="code" href="http://llvm.org/docs/doxygen/html/classllvm_1_1SmallVectorImpl.html" style="color: rgb(0, 0, 255); cursor: pointer; text-decoration: none; ">SmallVectorImpl</a><T>(NumTsAvailable)"</span></div>
<div> </div><div>SmallVector is telling SmallVectorImpl how far past its own memory space it can walk... <br><br>So my use of SmallVectorImpl was probably entirely erroneous/unsafe/broken.<br><br>Perhaps SmallVectorImpl's ctor should be protected and/or it could use CRTP to access the size as a compile-time constant (rather than a ctor argument) from the derived type?</div>
<div>Hmm, it's using it to runtime initialize the capacity pointer anyway... which only works because this thing never shrinks (so it doesn't have to remember how big the reserved space is because it'll never try to fit back into it if it outgrows it), so no real benefit to initializing the capacity as a compile time constant unless shrinking was supported (it'd save remembering the value as a runtime variable).</div>
<div><br></div><div>Fun times,</div><div><br></div><div>- David</div></div>