KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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?
Tags (comma-separated)
Save Edits
Cancel