DIP 1014
Manu
turkeyman at gmail.com
Sun Sep 30 07:26:51 UTC 2018
On Sat, Sep 29, 2018 at 11:50 PM Walter Bright via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On 9/29/2018 9:34 PM, Manu wrote:
> > GNU's std::string implementation stores an interior pointer! >_<
> >
> > No other implementation does this. It's a really bad implementation
> > actually, quite inefficient. It could make better use of its space for
> > small-strings if it wasn't wasting 8-bytes for an interior pointer to
> > a small string buffer...
>
> Could you post a synopsis of the layout of std::string?
The code's all in the PR if you wanna dig into it.
The synopsis is:
struct string
{
char* ptr;
size_t len;
union
{
char[16] localBuffer;
size_type allocatedCapacity;
}
bool isAllocated() { return ptr != &localBuffer[0]; }
bool capacity() { return isAllocated() ? allocatedCapacity :
localBuffer.length; }
this(DefaultCtor) { ptr = &localBuffer[0]; } // <- and here it is.
interior pointer that breaks move semantics
}
Other implementations make much better use of that built-in space by
not wasting 8 bytes on an interior pointer for small-strings.
More information about the Digitalmars-d
mailing list