How to make subsequent instances of the assembly shared memory?

I want something like a static class variable, except when different applications load my assembly. I want them all to share the same variable.

I know that I can write to disk or to the database, but this is for the process that is used with sql queries, and this will probably slow it down too much (actually I'm going to check these parameters, but I ask this question by time b / c I don't think this would be an acceptable solution).

I would prefer to use a solution that will entail the least overhead in the deployment, and I do not mind if the solution is not so easy to create, if it will be easy to use when I am done.

I know that there are some persistent memory frameworks. I have not tested any of them yet, and perhaps one of them would be perfect, so feel free to recommend it. I also completely agree to write something myself, especially if it makes deployment easier for me.

Thanks in advance for any suggestions!

Edit: Looks like I was looking at a very simple solution. My problem was that SQL provided only 8000 bytes of space for serializing data between calls to the aggregated SQL function that I wrote. I read an article on how to compress your data and get the most out of these 8000 bytes, and suggested that I can do nothing more. As it turned out, I can set MaxBytes = -1 instead of a range from 0 to 8000 to get up to 2 GB of space. I believe that this was something new that they added to the 3.5 framework, because there are various articles that talk about this 8000 byte limit.

Thanks to everyone for the answers, though, since this is a problem that I wanted to solve for other reasons in the past, and now I know what to do if I need a very simple and quick way to communicate between applications.

+4
source share
3 answers

You cannot store this as data in memory and share it between processes, since each process has its own isolated memory address space.

One option, however, would be to use a .NET-enabled memory file to β€œstore” shared data. This will allow you to write a file containing information in a place that each process can access.

+5
source

Each process has its own address space. You cannot just pass the variable as you intend

You can use shared memory .

If you are using .NET 4, you can simply use Memory Files

+2
source

If you need some kind of counting or locking across the entire machine, you can explore the use of named synchronization objects such as a semaphore - http://msdn.microsoft.com/en-us/library/z6zx288a.aspx or mutexes http: / /msdn.microsoft.com/en-us/library/hw29w7t1.aspx . When a name is specified, such objects are common to the whole machine.

+1
source

Source: https://habr.com/ru/post/1380491/


All Articles