"1) I believe, that your question does not really belong to this group, because
it is not a discussion of the existing standard, but a proposal of a new
feature. For this you better should use the std-proposals group:"
I thinks the question fits both groups as I want to know how much memory
standard containers requests from its allocator. I can re-post it anyway on
std-proposals if I am wrong.
"2) From your suggestion it did not really became clear to me, to which
class(es) you suggest to add this static member function. You should clarify
that. For the moment I assume you suggest to add this member to all standard
container classes."
Sorry for not making this point clear, my primary interest is having this
member function on node-based containers. However, I think it would a useful
addition for other containers as well.
"If you suggest to add this function to containers, you impose stronger
requirements on these containers."
Yes, this is true and intended.
"In fact, you require them not to take advantage of runtime-properties of the
system."
I do not agree with this statement. You can take advantage of the
runtime-properties either on the container side or on the allocator side. I
think that the allocation logic should be kept on the allocator and not split
between the container and the allocator. The allocator knows the type for which
it is allocating memory and can use this information. If you have a fancy
allocation algorithm why put it into the container instead of the allocator?
"This looks like a severe constraint to me for a feature that is only relevant
for a very narrow use-case of a very specific allocator that requires static
information to decide it's optimal management."
I think that it is a rather common situation that users know how big a
container will grow or at least have an upper bound on it. If this requirement
is too strong I would be also happy with non-constexpr function, so that I can
at least use an std::vector as a buffer instead of an std::array.
"If you are interested in such static policies you either need to provide your
own container that is happy with providing such a static information ..."
That is what I am trying to avoid since I believe this function could be easily
implement. I may be wrong but on libstdc++ for example, I see that std::set and
std::map could have this function implemented as
static constexpr std::size_t memory_consumed(size_type n_elements)
{return (n_elements + 1) * sizeof (node_type);}
where the "+ 1" accounts for the head node in the underlying red-black tree.
"Furthermore I believe that your suggestion is a bit of a red herring, because
the suggested function is only useful, if the actual number of elements is a
constant expression and I doubt that this is often the case."
I think it is very often the case in node based containers. In all cases I am
aware of the memory requested from the allocator is simply the number of
elements times the node size (and perhaps one more node that is used as head in
binary trees for example).
"To defend your suggestion I therefore strongly suggest to provide a reasonable
usage-example of your suggested new feature, so that it is easier to analyze
under which conditions it can actually become useful."
Every allocator that uses pre-allocated buffer is an usage-example. Without this
feature I am either running out of memory or wasting it. What buffer
size should I use?
Greetings from Atibaia,
Marcelo
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
std-discussio...@isocpp.org.
> To post to this group, send email to
std-dis...@isocpp.org.
> Visit this group at
http://groups.google.com/a/isocpp.org/group/std-discussion/.