Solved

Specifying default allocator

Posted on 2009-07-10
6
190 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
  • 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now