STL: malloc_alloc - omission of types

S

Shoban Jeyaraj

Hello,

I am an newbiew with respect to creating custom allocator. Currently,
we are in the process of creating a custom allocator. Going through
most of the example, we have one which requires to specify the type
while specifying the allocator:

Eg: vector<int, my_allocator<int> > foo;

I know that the default allocator malloc_alloc does not require the
type.

Eg: vector<int, malloc_alloc> foo;

I am wondering how it is implemented. Going through the STL source
(stl_alloc) does not help me much. Hope someone can clarify.

Regards,
Shoban Jayaraj
 
N

Nick Hounsome

Shoban Jeyaraj said:
Hello,

I am an newbiew with respect to creating custom allocator. Currently,
we are in the process of creating a custom allocator. Going through
most of the example, we have one which requires to specify the type
while specifying the allocator:

Eg: vector<int, my_allocator<int> > foo;

I know that the default allocator malloc_alloc does not require the
type.

malloc_alloc is not the default allocator.
Eg: vector<int, malloc_alloc> foo;

I am wondering how it is implemented. Going through the STL source
(stl_alloc) does not help me much. Hope someone can clarify.

Where are you getting your "STL" source from?
Regards,
Shoban Jayaraj

P.S. I think it is highly unlikely that this is a good idea anyway.
 
A

Alberto Barbati

Shoban said:
I know that the default allocator malloc_alloc does not require the
type.

Are you, by chance, using a very old SGI STL implementation? You should
know that allocators changed a lot since that implementation was
written. That implementation, although still good and honorable, is now
far from "standard". In particular, SGI STL allowed the member function
allocate() to return a void* but the C++ standard now mandates that it
shall return a typed pointer. That's why malloc_alloc does not require a
type but conforming allocators do.

Alberto
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top