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

  • Home
  • SEARCH
  • 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 216883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:36:21+00:00 2026-05-11T18:36:21+00:00

One of the libraries we are using for our product uses a singleton for

  • 0

One of the libraries we are using for our product uses a singleton for access to it. I’m pretty sure it’s implemented as a static instance (it isn’t open source). This works well for a single document application, but our app may have more than one document loaded. I’m assuming access to the instance is written something like this:

Instance* getInstance() {
    static Instance* inst = new Instance();
    return inst;
}

In situations like this, is there some way to robustly create more than
one instance? The only thing I can think of is to have more than process and use some type of IPC to tie it all together. I can’t think of anything less hacky.

I have asked the vendor to implement some type of session token so I can have multiple concurrent instances, but they are big and we are small.

Cory

Edit:

  • the machine is a Windows machine
  • the global static is basically a big factory. I want a session token of some type so I can easily say “release all the resources from this session” (there’s no way to re-initialize the global statics that I know of)

Rather than try some dodgy shenanigans to get what I want, I’m going to wrap the whole thing with my own class and add a session key to every getter. Internally I’ll keep track of what has been allocated add my own release method to return resources. This is suboptimal for lots of reasons, but I can’t think of a better idea.

Thanks to everybody for the great feedback.

  • 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-11T18:36:21+00:00Added an answer on May 11, 2026 at 6:36 pm

    The only thing that I can think of is to sub-class it if you are lucky enough to have the singleton class defined like:

    class Document {
    public:
        static Document* getInstance() {
            static Document inst;
            return &inst;
        }
        virtual ~Document();
    protected:
        Document();
    private:
        struct Impl;
        Impl *pImpl;
    };
    

    If you can subclass it and the subclass will have access to the constructor, then you can create an instanceable subclass like:

    class MyDocument: public Document {
    public:
        MyDocument(): Document() {
        }
    };
    

    This might not be completely safe since the implementer may have made some nasty assumptions. But it is an idea or some approach that might have some chance of working. With any luck the vendor might be amenable to this option if you mention it… good luck.

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

Sidebar

Related Questions

I have just started with using boost libraries. For one of our projects i
I am considering releasing one of my class libraries written in C# as open
I have a collection of static libraries (.lib) files one of which may have
If while an application is running one of the shared libraries it uses is
I have a website where everytime one of our customers reviews a new product
When compiling our project, we create several archives (static libraries), say liby.a and libz.a
In our iPhone XCode 3.2.1 project, we're linking in 2 external static C++ libraries,
I'm working on a small project with one other developer. We are using libraries
We're using cakephp 1.2 version for one of our newly developing project, so would
We've recently been asked to ship a Linux version of one of our libraries,

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.