tags:

views:

389

answers:

1

I am using a Memory mapped file to cache a large amount of data for an ASP.NET application. At the moment I am using the global.asax event to open the file and get a memory mapped file handle which I cache in the application object. If I dereference that handle to a pointer and try to cache the pointer in my httphandler, I get a protection exception when I reference the pointer so I am caching the handle to the Memory Mapped File and dereferencing it to a pointer inside my httphandler. This seems to work fine and is pretty quick so I am assuming it is only loading the file into real memory the once. The problem is that when the load increases I get multiple httphandler instances running at the same time and each one seems to dereference the handle to a different address. This results in running out of address space pretty quickly. Short of going to 64 bit, is there some way to force managed code to share a common chunk of memory between threads? Is there a better way to acomplish what I am trying to do here?

Thanks in advance,

Brian

A: 

I guess you could provide the pointer to the memory mapped file from a singleton, right?

lothar
No, as soon as you try to use the pointer in managed code you get a protection violation so the CLR is not happy trusting that memory it doesn't know about is safe to use. I suppose the next step is to explore the UNSAFE keyword but I was hoping to keep this available to VB programmers.
If the idea was to keep the handle and derefference it in code protected by the singleton, it would put a severe crick in the scaleablity as I use the memory for most of the process.