I was looking through custom allocators. For example std::set is defined as follows:
What I find odd about this is that the allocator here apparently only allocates integer. A set will use an AVL tree or red-black tree internally, however, and each element inside a set will need more information than just the stored value. For example, each node in the tree will at least contain two child nodes.Code:template < class Key, class Compare = less<Key>, class Allocator = allocator<Key> > class set;
Imagine a set of integers: the allocator will only be able to allocate integers. So how does it work internally? Does it allocate the tree's nodes simply by using "new", bypassing the allocator, and store a pointer to the allocated integer in the node?
That sounds to me as though it kind of defeats the purpose of the allocator, especially if it's used as optimization, for example using memory pools. Or am I missing something here?
Thanks in advance,