jeudi 17 octobre 2019

How to allocate std::map's internal RB_tree node in memory pool in C++11?

std::map definition is copied below:

template<
    class Key,
    class T,
    class Compare = std::less<Key>,
    class Allocator = std::allocator<std::pair<const Key, T> >
> class map;

Based on std::map definition, we can provider customized allocator for its Key and Value.

Questions:

  1. In most situations, std::map is implemented by RB tree. How can we provide customized allocator for RB tree node? I am afraid that we can not do it.
  2. If the answer to the first question is that we can NOT provide customized allocator for RB tree node, we can NOT provide customized allocator for other node-based containers (for example, std::list and std::set), either. Please confirm if my understanding is correct.

Thanks a lot.

Aucun commentaire:

Enregistrer un commentaire