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: Umara Dissanayake <umaradissa at gmail dot com>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 29 Aug 2013 17:36:12 +0530
- 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> <CAH6eHdR7onuEpxYA+gAdyxJvSX+4pRD-_xXAwbouN-ZYH2dCAg at mail dot gmail dot com>
So sorry Jonathan I actually had the issue in stl_map.h
129 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
130 key_compare, _Pair_alloc_type> _Rep_type;
I can't see where _Rb_tree is defined? stl_tree.h is not included by
stl_map? What am I missing?
On Thu, Aug 29, 2013 at 5:20 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> 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;