C++ Logo

std-proposals

Advanced search

Re: [std-proposals] C++ never had a compiler without a stack

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 14 Aug 2023 11:29:17 -0700
On Monday, 14 August 2023 09:23:47 PDT Henry Miller via Std-Proposals wrote:
> I'd prefer the standard allow/require unique_ptr, shared_ptr, make_unique,
> make_shared (and others) to implement automatic storage of T within the
> size allocated on the stack for the pointer if it meets some criteria.
> Most implementations of string have small string optimizations similar to
> that. I don't know if that change can be done without breaking ABI, but
> this is conceptually a better plan. I don't want developers to use a c++
> alloca for arbitrary large objects they think should go on the stack.
> However for small objects I suspect putting them on the stack can be a
> performance win without unduly making the stack too large.

It doesn't make sense for those types; see Jason's reply.

But it does for things like std::function and in fact the implementations do
have a "small object optimisation" for those for when the payload is a regular
function pointer, pointer to member function, or empty functor. I don't know
if it is required by the standard; if it is, it's the same as just saying
"shall not throw if the argument is a function pointer or pointer to member
function".

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

Received on 2023-08-14 18:29:19