Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6956039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:48:58+00:00 2026-05-27T14:48:58+00:00

Let’s say I create a linked list in STL: list<int, my_allocator<int> > data; Then

  • 0

Let’s say I create a linked list in STL:

list<int, my_allocator<int> > data;

Then I can use a more efficient allocator, let’s say a memory pool. But doesn’t the list need to allocate internal memory like forward and backward pointers to traverse the list? How will these be allocated? Using normal new or somehow using my_allocator?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:48:58+00:00Added an answer on May 27, 2026 at 2:48 pm

    The container does indeed repurpose your allocator to allocate its own book-keeping material. (Not that it would matter for a std::list, but it’s true in general.*) This is why the standard allocator requirements mandate the existence of the rebind template:

    typedef typename Alloc::template rebind<MyInternalStuff>::other internal_allocator;
    

    If your allocator is Alloc = my_allocator<T>, then internal_allocator becomes my_allocator<MyInternalStuff>.

    I believe that this was one of the gripes that Electronic Arts had with the C++ standard library, which is why their EASTL library uses a different convention for allocators that offers tighter control.

    *) Typically, each node will be one monolithic object of some type Node<T>, so I suppose std::list<T, Alloc> only ever uses Alloc::rebind<Node<T>>::other as an allocator.

    [Sorry for the multiple edits; I had the output mangled up and didn’t interpret it correctly; I now went and printed each container separately and fixed the output up accordingly. std::list does indeed only require one allocator.]


    Update: Just for giggles, I wrote a little demangling-allocator which prints its own typename upon construction. Here’s the input:

    #include <unordered_map>
    #include <set>
    #include <deque>
    #include <list>
    #include <vector>
    #include <map>
    
    #include <iostream>
    
    int main()
    {
      std::cout << "----- unordered_map<int, double> -----------" << std::endl;
      std::unordered_map<int, double, std::hash<int>, std::equal_to<int>, funky_allocator<std::pair<const int, double>>> m { {1, 1.2} };
      std::cout << "----- set<int> -----------------------------" << std::endl;
      std::set<int, std::less<int>, funky_allocator<int>> s;
      std::cout << "----- deque<int> ---------------------------" << std::endl;
      std::deque<int, funky_allocator<int>> d;
      std::cout << "----- list<int> ----------------------------" << std::endl;
      std::list<int, funky_allocator<int>> l;
      std::cout << "----- vector<int> --------------------------" << std::endl;
      std::vector<int, funky_allocator<int>> c;
      std::cout << "----- map<int, bool> -----------------------" << std::endl;
      std::map<int, bool, std::less<int>, funky_allocator<std::pair<const int, bool>>> n { { 1, true } };
    }
    

    And here the output:

    ----- unordered_map<int, double> -----------
    Default-construct: funky_allocator<std::pair<int const, double> >
    Copy-construct:    funky_allocator<std::__detail::_Hash_node<std::pair<int const, double>, false> >
    Copy-construct:    funky_allocator<std::__detail::_Hash_node<std::pair<int const, double>, false>*>
    
    ----- set<int> -----------------------------
    Default-construct: funky_allocator<std::_Rb_tree_node<int> >
    
    ----- deque<int> ---------------------------
    Default-construct: funky_allocator<int>
    Copy-construct:    funky_allocator<int*>
    
    ----- list<int> ----------------------------
    Default-construct: funky_allocator<std::_List_node<int> >
    
    ----- vector<int> --------------------------
    Default-construct: funky_allocator<int>
    
    ----- map<int, bool> -----------------------
    Default-construct: funky_allocator<std::_Rb_tree_node<std::pair<int const, bool> > >
    

    The details vary depending on which constructor is used: Containers like set and map might only construct the “correct” allocator in some invocation, while in another they may construct an object of the specified allocator first. Either way, the specified allocator never gets used at all for a couple of containers, and only the rebound version is used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you create a wizard in an HTML form. One button goes back,
Let's say I'm building a data access layer for an application. Typically I have
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I can call a method like this: core::get() . What is the
Let's say there is a graph and some set of functions like: create-node ::
Let's say I have some text as follows: do this, do that, then this,
Let's say I have the following entity: public class Store { public List<Product> Products
Let's say, I have a .NET 2 installed. Can I programmatically install version 4
Let's say an Owner has a collection of Watch(es). I am trying to create
Let's say I create an object like this: Person: NSString *name; NSString *phone; NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.