This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: stl_map Implementation Details for Development of Custom Allocator


On 29 August 2013 05:17, Umara Dissanayake wrote:
> Hi,
>
> I have noticed in my development of a customized allocator for maps
> that the library calls the templated copy constructor in the allocator
> class each and every time the map is accessed (ex - through
> operator[])

Not every time it's accessed, only when creating/destroying nodes.

> I understand that the templated copy constructor needs to be called to
> get an allocator which can handle memory requests for Rb_Tree_Nodes.
> What puzzles me is why this conversion couldn't be done once and the
> resulting node allocator be used thereon after without converting the
> allocator each and every time - which could be a hit on performance.

The map needs to use Alloc<_Rb_tree_node> to allocate memory for a
node, but it needs Alloc<value_type> to construct the element in the
node, so the map either needs to store an instance of both
specializations or  it needs to store one and rebind it to get an
instance of the other specialization as needed.

However I have reported a defect against the standard regarding that
requirement, see http://cplusplus.github.io/LWG/lwg-active.html#2218
In C++11 mode my proposed change would allow the allocator to store an
instance of Alloc<_Rb_tree_node> and to also use that same instance
for constructing elements.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]