Skip to main content
GameDev.net gamedev.net
🔒 Locked

shared_ptr custom deallocator

Started by templewulf Mar 14, 2006 at 7:18 PM 2 replies 3.8k views
Original Post
templewulf
templewulf
I've googled (and icerocketed) custom deallocators to parameterize shared_ptr, but I haven't found how to create one. Really, I just want a no-op deallocator to make shared_ptr not corrupt the heap when SDL_Quit and shared_ptr try to deallocate the same thing. Can anyone guide me to a better explanation of shared_ptr's custom deallocators? (Be gentle, I'm new to boost!)
XBox 360 gamertag: templewulf feel free to add me!
jpetrie
jpetrie
Here, check the docs for the second constructor, they describe what you are looking for I think.

You must pass a template parameter d (of type D) for which the expression d(p) is well formed (p is the raw pointer). For example:

void DeleteFn(SDL_Surface *p){  /* do what you need to p */} boost::shared_ptr< SDL_Surface > ptr(new SDL_Surface,DeleteFn);


should work; DeleteFn will be called when the pointer should be destroyed. I don't know SDL so my practice of "new SDL_Surface" is probably not the way your actually creating the surface, but you should get the idea.
templewulf
templewulf
Oh...so I can just use a function pointer? I guess it was just TOO obvious, huh? [lol]

Is there a generic no-op deallocator in std or boost? Really, I just need it to not delete SDL_Surface. I could just use SDL_Surface*, but I'd like to know anyway.

I'd give you a Ratings++, but you're already 1337. You were awfully helpful! [smile]
XBox 360 gamertag: templewulf feel free to add me!
Fruny
Fruny
Quote:
Is there a generic no-op deallocator in std or boost?


Not that I am aware of, but I trust you should be able to write one such. [grin]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

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

Sign in to reply to this topic.