Skip to content
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

Closed
ZhuYajunFly opened this issue Jul 14, 2024 · 12 comments
Closed

Add a type static class at the CLR level #104869

ZhuYajunFly opened this issue Jul 14, 2024 · 12 comments

Comments

@ZhuYajunFly
Copy link

ZhuYajunFly commented Jul 14, 2024

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
image
The App1 and App2 both ref the GlobalData project,gui is simple,a textbox to show,two btns for read and write data.
image
image
When you read write data,you will find the static class are diff instance in clr.
image
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.

@ZhuYajunFly ZhuYajunFly added the tenet-performance Performance related issue label Jul 14, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jul 14, 2024
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@huoyaoyuan huoyaoyuan removed the tenet-performance Performance related issue label Jul 14, 2024
@huoyaoyuan
Copy link
Member

Can you explain what does "type static class" mean? It's unclear in the original post.

@timcassell
Copy link

Do you mean the Singleton Pattern?

@ZhuYajunFly
Copy link
Author

Do you mean the Singleton Pattern?

thank you,singleton maybe not work with diff app to share data,because the static class not work.

@ZhuYajunFly
Copy link
Author

Can you explain what does "type static class" mean? It's unclear in the original post.

thank you, i add more detil in head,and to example. i hope you can understand witch i want that .

@timcassell
Copy link

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.

@ZhuYajunFly
Copy link
Author

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!

@huoyaoyuan
Copy link
Member

huoyaoyuan commented Jul 15, 2024

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.

@ZhuYajunFly
Copy link
Author

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? 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;

@ZhuYajunFly
Copy link
Author

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.

https://en.wikipedia.org/wiki/Shared_memory Shared memory,it work like.but now Shared memory use it not easy,should more improve it.

@huoyaoyuan
Copy link
Member

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.

@mangod9 mangod9 removed the untriaged New issue has not been triaged by the area owner label Jul 15, 2024
@mangod9 mangod9 added this to the Future milestone Jul 15, 2024
@AaronRobinsonMSFT
Copy link
Member

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.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants