Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ATronic

New: results?

This topic is 6107 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 never extensivly used dynamic memory allocation until recently. I was wondering how, when using New, to check to see if the allocation worked. Such as, what if there is not enough memory? I know you can check this somehow, but how? This is an obvious one I know, but searches yielded nothing on the forums. Google gave me info on new, but I found nothing on error handling. Thanks a ton! Alex Broadwin A-Tronic Software & Design ----- "if you fail in life, you were destined to fail. If you suceed in life, call me." "The answer is out there." "Please help, I''m using Windows!"

Share this post


Link to post
Share on other sites
Advertisement
In MSVC new returns a NULL pointer if an error occurs, i dont know what other compilers do but the standard states that operator new should throw an exception on error.

This should be in the MSDN...

Share this post


Link to post
Share on other sites
new should throw an exception if it fails, unless you use the non-throwing form of new, which returns NULL.

MSVC++ 6 returns NULL instead, though.

Share this post


Link to post
Share on other sites
But if that bugs you, you could always look up the function set_new_handler(), to make new throw an exception when memory allocation fails.

Share this post


Link to post
Share on other sites

  • 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!