C++ Logo

std-proposals

Advanced search

Re: Avoid copies when using string_view with APIs expecting null terminated strings

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 26 Dec 2020 17:03:34 -0300
On Saturday, 26 December 2020 03:38:20 -03 Tony V E via Std-Proposals wrote:
> An implementation can probably hide the ‎bool inside an unused bit of the
> pointer (or length), so it can still be 16 bytes.

TNSTAAFL

You may avoid a 50% growth in the class's size by introducing a data
dependency on an operation to remove that bit. That isn't free either and,
depending on how you model your cost, it could cost more than the size growth.

A third option is to use one of the unused bits in the pointer on CPUs that
support address masking / colouring. AArch64 has that and x86 published an
Instruction Extension a few days ago for this ("Linear Address Masking").
Since this is still upcoming technology, we'll probably still be discussing
systems without masking capabilities well after Jan 19, 2038.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DPG Cloud Engineering

Received on 2020-12-26 14:03:41