Jump to content

Very quick question regarding single-instance/singleton classes


Kevin3374

Recommended Posts

When you implement a single-instance class, it allows one instance of this class for each instance of the script correct?  In other words if 5 people are accessing the same script simultaneously, they each have their own instance of the class.  But each individual user cannot create more than one instance of this class, correct?

Link to comment
Share on other sites

You are correct.  If there are 10 simultaneous requests from different users, then they will each get their own instance of the singleton.  AFAIK, there is no built in mechanism to share data and objects between requests, but I've never looked into it.

 

If you did want to share data between requests, then I'm sure you could.  If there isn't a built in mechanism you could develop one of your own via permanent storage like a database.  However you'd have to deal with broadcasting changes to the data, which I'm not sure how you'd accomplish that.

Link to comment
Share on other sites

You are correct.  If there are 10 simultaneous requests from different users, then they will each get their own instance of the singleton.  AFAIK, there is no built in mechanism to share data and objects between requests, but I've never looked into it.

 

If you did want to share data between requests, then I'm sure you could.  If there isn't a built in mechanism you could develop one of your own via permanent storage like a database.  However you'd have to deal with broadcasting changes to the data, which I'm not sure how you'd accomplish that.

 

Thank you.  Good explanation.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.