C++ Logo

std-proposals

Advanced search

Re: [std-proposals] [[packed]] std::unaligned

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 18 Dec 2023 10:00:17 -0300
On Monday, 18 December 2023 09:28:38 -03 Frederick Virchanza Gotham via Std-
Proposals wrote:
> Although if a container is re-allocating, for example if an
> 'std::vector' wants to do 'push_back' but hasn't got enough free
> space, then it might be more efficient to also have a "relocate_n"
> function whose arguments must be correctly aligned, as follows:

That's hyper- and micro-optimisation. The compiler is perfectly able to see a
function called in a loop and perform hoisting of portions, splitting the
loops, etc. I expect that a vector relocating std::strings to be a point of
particular attention to the compiler vendors, so this code shouldn't be
needed.

At least, it shouldn't be needed unless proven to be needed. For example, if
you want to use realloc().

PS: obviously those functions should be friends of std::basic_string. If
you're going to show what they should look like, do it right.

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

Received on 2023-12-18 13:00:20