• Advertisement
Sign in to follow this  

shared_ptr custom deallocator

This topic is 4361 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

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<SDL_Surface> 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!)

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


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

  • Advertisement