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 7170365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:11:53+00:00 2026-05-28T15:11:53+00:00

In C++, I use a singleton class and refer to the only instance in

  • 0

In C++, I use a singleton class and refer to the only instance in another class. I’m wondering what is the most efficient way to access this instance since it is a large data structure. I considered these things.

  1. Getting a reference from the singleton class, other than passing the data structure by value
  2. Using a global instance in my second class which uses the singleton class:

    Singleton* singleInstance;
    
    SingletonUser::SingletonUser ()
    {
        singleInstance = Singleton::getInstance(); //passes the single instance by   reference, then it will be used in the class wherever needed
    }
    
  3. Doing the same thing inside a function of the second class so that I get a reference to the singleton class’s instance when I want it (Need to access it several times in several functions).

I’m not sure which practice is the best one. Can someone explain, and if there is a more efficient way, explain that too?

Thanks!

  • 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-05-28T15:11:54+00:00Added an answer on May 28, 2026 at 3:11 pm

    If you’re passing your singleton instance by value, then it’s not really a singleton, is it?

    Simply return a reference (or a pointer) to the instance whenever you need to access it (#1). Caching the reference once for each client is only going to add complexity and almost certainly won’t be any faster.

    I’m not sure what the difference is between #1 and #3, besides added complexity. Both use a function to access the singleton instance via a reference/pointer.

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

Sidebar

Related Questions

I have a C# singleton class that multiple classes use. Is access through Instance
I'd use a singleton like this: Singleton* single = Singleton::instance(); single->do_it(); I'd use an
I tried to implement a singleton class in the following way (I use VS2008
When I try to use this one approach of singleton: class Singleton(object): def __init__(self,
When should you NOT use a singleton class although it might be very tempting
The singleton is explained here: http://en.wikipedia.org/wiki/Singleton_pattern#PHP_5 . I want to use the singleton class
In all my projects till now, I use to use singleton pattern to access
Should Singleton objects that don't use instance/reference counters be considered memory leaks in C++?
I have a singleton object that use another object (not singleton), to require some
I'm trying to create a simple to use singleton class to connect to mysql

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.