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?

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.

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.

Archived

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

×
×
  • 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.