cppalliance / http_proto

HTTP/1 parsing and serialization algorithms using C++11
https://develop.http-proto.cpp.al/
Boost Software License 1.0
23 stars 10 forks source link

fields_base allocation behavior #68

Closed cmazakas closed 5 months ago

cmazakas commented 6 months ago

fields_base needs a means of controlling how it allocates.

For this, a two argument overload is introduced along with 2 convenience overloads.

Consider: fields_base(size_type initial_size, size_type max_size);

The container will not allocate beyond max_size and requests for memory will throw bad_alloc (or similar).

fields_base(0, 16 * 1024) is permitted, and will not allocate.

fields_base() can then become fields_base():fields_base(0, max_size_) where max_size_ is some defaulted member, perhaps to size_type{-1}.

// synopsis
fields_base(size_type initial_size, size_type max_size);
fields_base(size_type size); // initial_size = max_size
fields_base() noexcept; // initial_size = 0, max_size = impl-defined