Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9060467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:14:15+00:00 2026-06-16T15:14:15+00:00

I am actually making a simple C++ SFML game and I want to learn

  • 0

I am actually making a simple C++ SFML game and I want to learn much more into C++ programming.

Now I am using shared_ptr to manage resources. I have some question about shared_ptrs when creating a new resource like:

    shared_ptr< Resource > resource( new Resource( World::LEVEL ) );

According to boost shared_ptr< class Y>( Y * p ) throws bad_alloc.
I dunno if std::tr1 does the same. And I do not know if I should worry about putting shared_ptr inside a try/catch block to check if bad_alloc is thrown. Is this a good programming practice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:14:16+00:00Added an answer on June 16, 2026 at 3:14 pm

    Per the C++ 2011 standard, §20.7.2.2.1 ¶6:

    template<class Y> explicit shared_ptr(Y* p);

    Throws: bad_alloc, or an
    implementation-defined exception when a resource other than memory
    could not be obtained.

    You catch exceptions when you know how to handle them. If you’re going to handle a out-of-memory exception and have code to do so, then by all means, put it in a try-catch. If you’re not writing mission-critical code and don’t expect to be operating on the edge of system memory constraints, it’s likely not necessary. Note that pretty much every line of code you write can throw exceptions once your system is out of memory.

    It’s important to note that on modern hardware/operating systems, “out of memory” doesn’t mean that you’ve exceeded the physical memory constraints – you can have only 128MiB of memory and not get an error even when you use 10 times that, and you can have 8GiB of physical memory and get that error when you’ve only used half that much. This refers to the memory space available to your application, which the OS will page to disk if necessary (and assuming available disk space).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple high scores database for an iPhone game using Amazon's SimpleDB
really simple question, just having a hard time actually making it work. I have
I am making a simple application and will require to actually load different views
Im working on making a simple Java game and had the great idea of
I want to implement a simple SceneGraph in Haskell using Data.Tree consisting of Transform
I am making a simple layout for a calculator, actually i am new to
I want to make a simple program. Don't really care what it does, actually.
I'm making an application using DDD principles. After thinking everything through as much as
so I'm making a really simple program in which I want one sprite to
Actually I am new to jquery as well as web designing Now I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.