<div class="gmail_quote">On 8 April 2012 17:52, Andrei Alexandrescu <span dir="ltr"><<a href="mailto:SeeWebsiteForEmail@erdani.org">SeeWebsiteForEmail@erdani.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 4/8/12 4:54 AM, Manu wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On 8 April 2012 12:46, Vladimir Panteleev <<a href="mailto:vladimir@thecybershadow.net" target="_blank">vladimir@thecybershadow.net</a><br></div><div><div class="h5">
<mailto:<a href="mailto:vladimir@thecybershadow.net" target="_blank">vladimir@<u></u>thecybershadow.net</a>>> wrote:<br>
<br>
    On Sunday, 8 April 2012 at 05:56:36 UTC, Andrei Alexandrescu wrote:<br>
<br>
        Walter and I discussed today about using the small string<br>
        optimization in string and other arrays of immutable small objects.<br>
<br>
        On 64 bit machines, string occupies 16 bytes. We could use the<br>
        first byte as discriminator, which means that all strings under<br>
        16 chars need no memory allocation at all.<br>
<br>
<br>
    Don't use the first byte. Use the last byte.<br>
<br>
    The last byte is the highest-order byte of the length. Limiting<br>
    arrays to 18.37 exabytes, as opposed to 18.45 exabytes, is a much<br>
    nicer limitation than making assumptions about the memory layout.<br>
<br>
<br></div></div><div class="im">
What is the plan for 32bit?<br>
</div></blockquote>
<br>
We can experiment with making strings shorter than 8 chars in-situ. The drawback will be that length will be limited to 29 bits, i.e. 512MB. </blockquote><div><br></div><div>29 bits? ...not 31?</div><div>How does this implementation actually work? On 32/64 bits, and little/big endian?</div>
<div>I can only imagine it working with a carefully placed 1 bit. bit-0 of the size on little endian, and bit-31 of the size on big endian. That should only halve the address range (leaving 31 bits)... where did the other 2 bits go?</div>
<div><br></div><div>I also hope this only affects slices of chars? It will ignore this behaviour for anything other than char arrays right?</div></div>