| icegood (42) | |||||||
I want to see how memory consumed by std::set, in particular how bytes are ordered for tree itself and data in that tree. So i just overrided allocator in next way:
I should explicitly write
instead of
because of special rules in templates inheritance mechanizm. But it seems that allocate wasn't overrided in that way. How to overcome such behaviour? | |||||||
|
|
|||||||
| cire (2357) | |
|
http://en.wikipedia.org/wiki/Allocator_%28C%2B%2B%29 Scrolll down to the requirements section. | |
|
|
|
| icegood (42) | |
| OK. But inheritance supposed to fulfii all conditions, isn't it? In fact, it is. At least code compiled and run. Or should i do smth like types redefinition? | |
|
|
|
| Cubbi (1927) | |
|
#define, really? Anyway, std::set does not allocate objects of type int. It allocates nodes of some tree, which have some other type (_Rb_tree_node<int> in GCC, for example). In order to allocate those nodes, it has to obtain a suitable allocator. To obtain that from the allocator you provided, it uses the rebind template. Since you derived your allocator from std::allocator, it sees the base class's rebind, which returns std::allocator<NodeType>, and that's what it uses to allocate those nodes. (those wikipedia requirements are pretty old now, c++11 made it so much easier to write allocators) | |
|
Last edited on
|
|
| icegood (42) | ||
|
Now i see! Thanks! P.S.
Why not in tests? :) | ||
|
|
||