Jump to content
  • Advertisement
Sign in to follow this  
jrmcv

new, delete, exceptions help needed

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

Hi, I have recently converted a lot of code from VC 6 to VC .Net and I am having a lot pf problems with the new memory exceptions. I could go through all the code and add in the try, catch lines but its not really a quick copy and paste job and each procedure is going to need a bit of thinking. Is there anyway I can force the new operator to return NULL on memory allocation errors? That way all my existing error handling will work. I know you can override the new and delete operators but I have found my program to run considerably slower (half speed on intensive memory allocation areas) when doing so. This isn't really that important as its only a demo app that is very unlikely to be distributed but its really starting to bug me now and I would like to fix it if possible. I guess i need a crazy quick-fix scheme for now. Thanks a lot in advance for any help you guys can give. P.S: I have quite a lot of existing code which is why i'm not dying to go through every line of code to make the changes. P.P.S : I am not too concerned with how clean or technically correct the solution is for this project. Just a fix will do for now. I'll do it the right way from the beginning for next projects. Thanks

Share this post


Link to post
Share on other sites
Advertisement
That isn't the best article on it. try searching around msdn for no throw

basiclly you can do this:
T* t = new (std::nothrow) T();
to get localized no throw behavior. There are a few other ways to get global nothrow behavior as well.

Share this post


Link to post
Share on other sites
I haven't tried it, but you could probably overload new to always do that. Then you wouldn't have to change your code at all.

I have no idea whether that would work, I've only overloaded new once a long time ago to help with memory leak detecting.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!