Skip to main content
gamedev.net
🔒 Locked

Good smartpointer lib.

Started by peter_b 5 replies 900+ views
Original Post
peter_b
peter_b
Hi, im looking for a smartpointer class lib that is as good and transparent as possible. That can handle custom memory deallocation such as dx video memory for instance. Which needs to call i->Release(); instead of delete i; (if that how you do it with custom memory? im not familiar with smart pointers) I have heard that std::auto_ptr has alot of problems, for instance that you cannot have a vector of auto_ptr, or if it was copying a vector, or something like that. Maybe some boost pointer? Basically what i want is memory management for c++.
Shields up! Rrrrred alert!
Nitage
Nitage
boost::shared_ptr has evrything you request.

By default it calls delete when the reference count hits 0, but that behaviour can be changed.
_goat
_goat
A good tip is to try and write one yourself, and then give up and use boost's shared_ptr. That way you'll have at least a decent understanding of what's going on behind the scenes.
krum
krum
Quote:
Original post by Nitage
boost::shared_ptr has evrything you request.

By default it calls delete when the reference count hits 0, but that behaviour can be changed.


Except for calling Release(). You can use ATL's CComPtr for that.
Nitage
Nitage
Quote:
Original post by krum
Quote:
Original post by Nitage
boost::shared_ptr has evrything you request.

By default it calls delete when the reference count hits 0, but that behaviour can be changed.


Except for calling Release(). You can use ATL's CComPtr for that.


I don't understand what you mean. Could you explain please?
Enigma
Enigma
Quote:
Original post by krum
Quote:
Original post by Nitage
boost::shared_ptr has evrything you request.

By default it calls delete when the reference count hits 0, but that behaviour can be changed.


Except for calling Release().

Including calling Release:
boost::shared_ptr< Class >(new Class(), std::mem_fun(&Class::Release));

Enigma
krum
krum
Quote:

Including calling Release:
boost::shared_ptr< Class >(new Class(), std::mem_fun(&Class::Release));

Enigma


Holy cow! You learn something new every day.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.