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 697359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:09:36+00:00 2026-05-14T03:09:36+00:00

I am trying to write a container class which uses STL allocators. What I

  • 0

I am trying to write a container class which uses STL allocators. What I currently do is to have a private member

std::allocator<T> alloc_;

(this will later be templated so that the user can pick a different allocator) and then call

T* ptr = alloc_.allocate(1,0);

to get a pointer to a newly allocated ‘T’ object (and used alloc_.construct to call the constructor; see the answer below). This works with the GNU C++ library.

However, with STLPort on Solaris, this fails to do the right thing and leads to all sorts of bizarre memory corruption errors. If I instead do

std::allocator_interface<std::allocator<T> > alloc_;

then it is all working as it should.

What is the correct way to use the stl::allocator? The STLPort/Solaris version fails to compile with g++, but is g++ right?

  • 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-14T03:09:36+00:00Added an answer on May 14, 2026 at 3:09 am

    Something you might want to do is have your own custom allocator that you can use to see how the standard containers interact wit allocators. Stephan T. Lavavej posted a nice, simple one called the mallocator. Drop it into a test program that uses various STL containers and you can easily see how the allocator is used by the standard containers:

    • https://devblogs.microsoft.com/cppblog/the-mallocator/

    Not all of the interface functions in the mallocator (such as construct() and destroy()) are instrumented with trace output, so you might want to drop trace statements in there to more easily see how the standard containers might use those functions without resorting to a debugger.

    That should give you a good idea of how your containers might be expected to use a custom allocator.

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

Sidebar

Ask A Question

Stats

  • Questions 502k
  • Answers 502k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer time: O(n) (One pass) space: O(k) This is how I… May 16, 2026 at 2:33 pm
  • Editorial Team
    Editorial Team added an answer Sorry I forgot to come back here with my solution… May 16, 2026 at 2:33 pm
  • Editorial Team
    Editorial Team added an answer Mathematically, I'm not sure exactly why Netwon's method fails, but… May 16, 2026 at 2:33 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to write a generic class which contains a generic TObjectList< T >
I've been trying to make some applications which all rely on the same library,
I'm trying to understand a line from the Google Datastore API which says: JDO
I'm writing some Scala code which uses the Apache POI API. I would like
The title might be a bit confusing, basically I'm trying to write up a
I am trying to write a query to pull all the rows that contain
I'm trying to write a query in Oracle SQL to access a particular substring
I have just started Entity Framework & linq and write this query var query
Trying to write a GLOBAL CBT HOOK, this is My code, but my hooking
In trying to write a simple C# ADO.NET application to connect to my database

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.