C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Static Allocator (All Containers Compatible with Microcontrollers)

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Wed, 3 Aug 2022 12:54:58 -0400
Broadly speaking, what you're asking for is not really viable.

The problem with simplistic, fixed-bound allocators like these is that
it only works while communicating effectively with the container
itself.

`vector`'s allocation strategy is entirely *opaque* to the user. In
your example, how do you as the user of `vector` know that the first
`push_back` won't try to allocate more than 4 characters? There's no
requirement than, when using `push_back` on an empty `vector`, it will
allocate a buffer of no more than 4 values. There's no requirement
that calling `reserve(x)` will only allocate `x` items.

Everything you want ultimately requires a tighter coupling between the
container and the allocator than C++ provides. The only way to resolve
this is to make some fundamental changes to the allocator/container
model.

Received on 2022-08-03 16:55:08