0

I have somewhat huge arrays (1 MB * 100) of raw byte data in my ASP.Net application. They need to get broadcast to several users very frequently.

A thread processes the data on the background and updates them from time to time.

Could you please give me suggestions on the best option to share the buffer between them?

Eric J.
  • 147,927
  • 63
  • 340
  • 553
beebee
  • 280
  • 3
  • 18

1 Answers1

2

That sounds like a good case for memory mapped files

A memory-mapped file contains the contents of a file in virtual memory. This mapping between a file and memory space enables an application, including multiple processes, to modify the file by reading and writing directly to the memory. Starting with the .NET Framework 4, you can use managed code to access memory-mapped files in the same way that native Windows functions access memory-mapped files

http://msdn.microsoft.com/en-us/library/dd997372(v=vs.110).aspx

http://msdn.microsoft.com/en-us/library/vstudio/system.io.memorymappedfiles.memorymappedfile

A thread processes the data

Is that an ASP.Net thread? I would not perform that type of task within the context of IIS (why not). Instead, I would propose the shared memory be managed by a separate process, outside of IIS, such as a Windows Service.

The memory mapped file mechanism is well-suited to a Windows Service updating the data, and individual ASP.Net worker threads accessing the data as needed.

Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • Thank you for the reply. I can use a windows server. However, the content come from another server through a socket and has no physical saved location in the server. Does that change your answer? – beebee Mar 25 '14 at 22:04
  • I'd back the memory mapping with a persistent file. That way the data will outlive worker-process recycling. +1 – usr Mar 25 '14 at 22:30
  • @beebee: I'm talking about a Windows Service, not Windows Server the operating system. It does not change my answer whether or not the data needs to be physically saved. As usr noted in his answer, a memory mapped file might be backed by a persistent file, but it need not be. It can exist only in virtual memory. – Eric J. Mar 26 '14 at 00:03