Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make subsequent instances of an assembly share the same memory?

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

I know I could write to disk or to a database, but this is for a process that's used with sql queries and that would probably slow it down too much (actually I am going to test these options out but I'm asking this question in the meantime b/c I don't think it's going to be an acceptable solution).

I would prefer to use the solution that incurrs the least overhead in deployment, and I don't mind if the solution isn't easy to create so long as it's easy to use when I'm done.

I'm aware that there are some persistent memory frameworks out there. I haven't checked any of them out yet and maybe one of them would be perfect so feel free to recommend one. I am also perfectly content to write something myself, particularly if it makes deployment easier for me to do so.

Thanks in advance for any and all suggestions!

Edit: Looks like I was overlooking a really easy solution. My problem involved SQL only providing 8000 bytes of space to serialize data between calls to a SQL aggregate function I wrote. I read an article on how to compress your data and get the most out of that 8000 bytes, and assumed there was nothing more I could do. As it turns out, I can set the MaxBytes = -1 instead of a range between 0 to 8000 to get up to 2gb of space. I believe that this was something new they added in the 3.5 framework because there are various articles out there talking about this 8000 byte limitation.

Thank you all for you answers though as this is a problem I've wanted to solve for other reasons in the past and now I know what to do if I need a really easy and fast way to communicate between apps.

like image 379
Brandon Moore Avatar asked Feb 23 '23 11:02

Brandon Moore


1 Answers

You can't store this as in-memory data and have it shared between processes, since each process has it's own isolated memory address space.

One option, however, would be to use the .NET Memory-mapped file support to "store" the shared data. This would allow you to write a file that contained the information in a place that every process could access.

like image 138
Reed Copsey Avatar answered Feb 25 '23 02:02

Reed Copsey