This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: stl_map Implementation Details for Development of Custom Allocator
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Umara Dissanayake <umaradissa at gmail dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 29 Aug 2013 12:50:10 +0100
- Subject: Re: stl_map Implementation Details for Development of Custom Allocator
- Authentication-results: sourceware.org; auth=none
- References: <CAE48+eX3OCegqCkd4SC1LgHu_aiA8ehXkgYG2qJZt8Esq4YbCg at mail dot gmail dot com> <CAH6eHdSVZS4bmZAM0C928HgZTwZr7uRWNJfYamdiXyirg7MuSw at mail dot gmail dot com> <CAE48+eWuNAYkU24U+RH3FmiubXLyWkYY1b7qm=WkaAdwKJC1Fg at mail dot gmail dot com> <CAH6eHdQwfZ+0pJNeWNGJbQ=o=E93xaFK_tzwHJXVU9QOPSSHYA at mail dot gmail dot com> <CAE48+eWCWA2Gt3uPWgo58MNV6VRLPN-2Xaa0VKPW-weFH5r+EQ at mail dot gmail dot com>
On 29 August 2013 12:19, Umara Dissanayake wrote:
> Hi Jonathan,
>
> Thanks for your reply.
>
> "To avoid the copy done by get_allocator() the container would have to
> store two allocator objects, which would increase the size of some
> maps. The design of the STL assumes copying allocators is relatively
> cheap"
>
> This is what I needed to know, exactly WHY this design decision was made.
Traditionally allocators are lightweight and stateless, so copying
them is cheap. Storing two separate objects is not necessary if
copying them is cheap. That's a decision made 15 years ago during
standardization of C++ 1998, partly because specifying the semantics
of stateful allocators was too complicated to get right at the time.
> I was proposing to have two pointers pointing to objects of
> Alloc<_Rb_tree_node> and Alloc<value_type>. Forgive my incorrect
> terminology I've only been programming in C++ for six months.
You don't need pointers to objects, you need the objects themselves.
>
>
> If you could indulge me for one more question.
>
> In the code for stl_tree, the member variable _M_impl is used in quite
> a number of places, though I cannot seem to be able to find its
> initial definition. Has this been defined in some other way than being
> included in header files?
It's defined in _Rb_tree, maybe you missed it:
_Rb_tree_impl<_Compare> _M_impl;