Jump to content
  • Advertisement
Sign in to follow this  
nuclear123

stl allocator object?

This topic is 2638 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

can anyone provide a simple example of what an allocator is used for? to me it just seems equivalent to auto_ptr

i dont understand the point of allocator class and why to use it

Share this post


Link to post
Share on other sites
Advertisement
It is there if you need to replace the default allocation strategy. A common example would be memory pooling. You probably don't need to use it. Allocators are weird, and somewhat compromised by design (in favour of performance).

It doesn't really have anything in common with auto_ptr<>.

Share this post


Link to post
Share on other sites

can anyone provide a simple example of what an allocator is used for? to me it just seems equivalent to auto_ptr

i dont understand the point of allocator class and why to use it

You are unlikely to need to use [font="Courier New"]std::allocator[/font]. It's a stateful memory allocator (like, say, [font="Courier New"]::operator new()[/font] or [font="Courier New"]std::malloc()[/font]) but with more advanced semantics like [font="Courier New"]rebind<>()[/font], and with in-built typedefs for sneaky things like proxied pointers. It (or a duck class providing identical semantics) is used in standard containers.

[font="Courier New"]std::auto_ptr[/font] is a deprecated class used to provide limited RAII semantics for pointers. I don't see how they are at all remotely similar. [font="Courier New"]std::auto_ptr[/font] has been replaced by [font="Courier New"]std::unique_ptr[/font] in the current C++ standard.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!