-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a type static class at the CLR level #104869
Comments
Tagging subscribers to this area: @mangod9 |
Can you explain what does "type static class" mean? It's unclear in the original post. |
Do you mean the Singleton Pattern? |
thank you,singleton maybe not work with diff app to share data,because the static class not work. |
thank you, i add more detil in head,and to example. i hope you can understand witch i want that . |
Oh, you want to share data between multiple processes. I think you can do that using the singleton pattern and a file (for serialized data) and a named Mutex. I'm not sure this is a good thing to add to the runtime. |
Sure,serialized data should work,but not flexible and not like memory-exchange that so high-performance.If one day,that you can easy to exchange data with a special static class(by class name and namespace),oh, so amazing! |
So you are asking for static data sharing between different processes. It's indeed a complex problem that can't be solved with such simple solution. How about the scope of sharing? How to handle processes with different privilege? How to verify the partner process is trusted, not malicious? How about compatibility between different CLR versions? It will also face the same safety problem with the already-deprecated implicit remoting and binary serialization. The best solution would be provided by the operating system, to properly share R/W data between processes. We can then build some API upon it at best. |
yes,with multi-threaded safety, not easy,but we can limit only .net apps can R/W,clr runtime know which app which thread use it,then can do something.also,we can use private prop,use method to R/W data , the method use lock to protect data multi-threaded safety; |
https://en.wikipedia.org/wiki/Shared_memory Shared memory,it work like.but now Shared memory use it not easy,should more improve it. |
It's not shared memory to be not easy. It's the problem itself to be complex. Shared memory is not fully owned by current process, so it's not a simple work or even impossible to adapt it with object and GC model. |
Runtime instances are independent of one another from each runtime's perspective. Having a built-in shared state mechanism is a non-goal of .NET. Creating a solution using a memory mapped file is the recommendation. |
Add a type static class at the CLR level,when any app the static class load in CLR, then all apps get only one Instance.
For multi-threaded safety,may add a key-word to decorate the static class.
For detail:
https://github.com/ZhuYajunFly/StaticClassDemo
I creat three project,the GlobalData provide data to other project, the App1 and App2 use the static class name of ShareData, i hope the static data in clr only one instance,but not.For easy to show,the static class only has one prop.
![image](https://private-user-images.githubusercontent.com/52872318/348581603-ad90cd1e-e206-4488-9afe-05456a5996c6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM5Njc5OTIsIm5iZiI6MTcyMzk2NzY5MiwicGF0aCI6Ii81Mjg3MjMxOC8zNDg1ODE2MDMtYWQ5MGNkMWUtZTIwNi00NDg4LTlhZmUtMDU0NTZhNTk5NmM2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE4VDA3NTQ1MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg1YWRjMzE1YjMwZGQ3ZTU5YmEzZWEyMGM0MjZhZDUwY2VhYmU2ODNhYzNlMzE2ZDU1YzVjMDFhNzY4MGEyMjImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.jRJyZH3aMGIiFc6XL8OQUvOVv3ISFxCC3j2nI3rYI_A)
![image](https://private-user-images.githubusercontent.com/52872318/348581425-c66f9ad1-8f56-41ea-8dbf-8df88503eb87.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM5Njc5OTIsIm5iZiI6MTcyMzk2NzY5MiwicGF0aCI6Ii81Mjg3MjMxOC8zNDg1ODE0MjUtYzY2ZjlhZDEtOGY1Ni00MWVhLThkYmYtOGRmODg1MDNlYjg3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE4VDA3NTQ1MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI5YzhhNWZlMDRkZWY3OTg2YmE3ZDlmZmNmZmVhYTJjODg5ZDBhMDNhMzMyZjU2NmI2NDE1ZGU0OWU5OTJmYjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.pwYVNH18V3QWz5DSxnzMg58X4JCMcOPpSz0jMC4cbTg)
![image](https://private-user-images.githubusercontent.com/52872318/348581830-99d2e4a7-1db8-46db-8d72-a75a7f640118.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM5Njc5OTIsIm5iZiI6MTcyMzk2NzY5MiwicGF0aCI6Ii81Mjg3MjMxOC8zNDg1ODE4MzAtOTlkMmU0YTctMWRiOC00NmRiLThkNzItYTc1YTdmNjQwMTE4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE4VDA3NTQ1MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTA1ZjMzZDVhOTkxMjhiOGY2ZTI0MmEyNzU4YTQ4NTU5Mzk0NGY3MzVmMGNmYzJiODE2ZTQwODcxNzNlN2Y2NzUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.EtQ7ZznbmM_OLy5ZPwycEH-PPfY1eVwsKCyXi-4Ox8g)
![image](https://private-user-images.githubusercontent.com/52872318/348581863-aecce30c-4d16-42a5-afca-0f344d1c8e97.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM5Njc5OTIsIm5iZiI6MTcyMzk2NzY5MiwicGF0aCI6Ii81Mjg3MjMxOC8zNDg1ODE4NjMtYWVjY2UzMGMtNGQxNi00MmE1LWFmY2EtMGYzNDRkMWM4ZTk3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE4VDA3NTQ1MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTRlNmYwMGVjOTk3NTQ2NTY5ODNhMTYyMDdjY2ExNjk2MmNiY2FlZGNmOGQxZjkyODUyMjgzNDcyNzM1NGI3ZDYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.DzbV77AOkDHfuCWrA5utrUyGCv2lSa6ESn9lJf4rTK8)
![image](https://private-user-images.githubusercontent.com/52872318/348581948-4a96df6c-433d-45b2-8a4c-0f261f98934f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM5Njc5OTIsIm5iZiI6MTcyMzk2NzY5MiwicGF0aCI6Ii81Mjg3MjMxOC8zNDg1ODE5NDgtNGE5NmRmNmMtNDMzZC00NWIyLThhNGMtMGYyNjFmOTg5MzRmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE4VDA3NTQ1MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI3ZTJjMmYzZWRhYjI3ODRhYzZhYjE4YjExM2JlMzEzM2ZhZmY4ZmJiOTRkZmQ3ZTIyZTcxZjFlNzYyYTM5Y2MmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.sidT0xFyghQt7JqnOPdK4yZz8arQq5PaBTNd1CZIckU)
The App1 and App2 both ref the GlobalData project,gui is simple,a textbox to show,two btns for read and write data.
When you read write data,you will find the static class are diff instance in clr.
So,I hope has a specicl static class in clr only one instance for diff apps to share datas,For multi-threaded safety,may add a key-word to decorate the static class.I know someting about redis,but it a little bit heavy,and use it not like static class with flexible and strong type cheack.
The text was updated successfully, but these errors were encountered: