Boost logo

Boost :

From: Christopher Kormanyos (e_float_at_[hidden])
Date: 2020-01-23 05:39:10

> I've been working on an AllocatorAwareContainer> called `dynamic_array` and was wondering if there'd> be any interest in including it in Boost.
I do not know about the general boost interest.But I find the dynamic array very useful andhave supported a similar utility in my own workin embedded microcontroller systems for over ten years.
> Naturally the question arises, "why use `dynamic_array`> in the year 2020 when we have `std::vector` and> `boost::allocate_unique`?".
For several reasons. The dynamic container isthought to be lightweight in the sense of not pullingin significant amounts of library code. In particularresource constrained systems with closely managedheaps need something like this. In the realm of embeddeddevelopment it can be important to allocate memoryup front at or near the time of static initialization.A kind of dynamic array allows for sizing withinconstructor initializer lists and other things usefulin this endeavor.
But how such a thing could or might fit into Boost,I do not know.

Kind regards, Chris.

    On Thursday, January 23, 2020, 5:04:51 AM GMT+1, Christian Mazakas via Boost <boost_at_[hidden]> wrote:
 I've been working on an AllocatorAwareContainer called `dynamic_array` and
was wondering if there'd be any interest in including it in Boost.

First and foremost, a link to the source code:

`dynamic_array` is a heap-allocated array that can't be resized (without
entirely re-assigning it). It's useful in cases where you'd normally use
`std::vector` but have no need of `push_back`, `emplace_back`, or any of
the other size modifiers that the container supports. These kinds of arrays
are typically useful in I/O applications which normally only accept a
pointer-size pair to write out to.

Naturally the question arises, "why use `dynamic_array` in the year 2020
when we have `std::vector` and `boost::allocate_unique`?".

`std::vector` imposes a constant storage cost of pointer, size, and
capacity. `dynamic_array` only stores a pointer and a size making it
slimmer in use-cases where there's no need of a separation between size and
capacity. `dynamic_array` also supports constructors `std::vector` doesn't
have. For example, `dynamic_array` is constructible from a Range and has a
`noinit` constructor. `dynamic_array` even supports array objects which
gives it another advantage.

`boost::allocate_unique` is a significantly tougher class to beat because
it boasts many of the same features: a dynamic allocation done using the
supplied Allocator supporting `noinit` construction and array objects with
a size (stored in the Deleter of the returned `std::unique_ptr`). And while
it is true that `boost::allocate_unique` enables all of this, it still
lacks a few key semantics.

Namely, `dynamic_array` is copyable. It's also copy assignable and move
assignable, including the case where the underlying allocators do not use
the same memory resource and will instead perform a piece-wise move of the

It's arguable whether or not `std::unique_ptr` should support similar
semantics so in the interim, `dynamic_array` is the next best thing.

- Chris

Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at