Solved

Specifying default allocator

Posted on 2009-07-10
6
230 Views
Last Modified: 2012-05-07
Hello.

If I have something like vector<int>, there is a default allocator given, I know that uses new(), but say I'm creating a new container class, how can I specify to use the default allocator as the STL container classes do?

template<typename TAllocator=???>

Thanks,
Uni
0
Comment
Question by:Unimatrix_001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 24828602
typedef vector<int, MyAllocator> MyVecType;
0
 
LVL 40

Expert Comment

by:evilrix
ID: 24828605
Sorry.. mis read... I'll try again...
0
 
LVL 40

Expert Comment

by:evilrix
ID: 24828610
struct MyAllocator // Must model an allocator concept
{
};

template < typename T, typename aT = MyAllocator>
struct MyVector
{
};
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24828616
But how about if I'm wanting the default allocator provided by the STL - i.e. vector<int> uses new(). How do I go about doing that?
0
 
LVL 40

Accepted Solution

by:
evilrix earned 500 total points
ID: 24828641
>> vector<int> uses new()
No, vector uses std::allocator

std::vector<T, std::allocator<T> >

template < typename T, typename aT = std::allocator<T> >
struct MyVector
{
};
0
 
LVL 3

Author Closing Comment

by:Unimatrix_001
ID: 31602330
Ah thank you. :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question