0

.NET 4.5, Win 8, 64bit

I have an IntPtr to 4 GB unmanaged array. I want to pass it async to a WCF NetPipes Windows Service, which is supposed to read it, push it to DB then deallocate it.

I am aware that the caller and the callee are on two different appdomains, so this might not be possible.

Is this possible and how?

Ofcourse, I can copy the data to a managed array then pass the managed array to the service, but this is not good performance-wise.

N.B. I asked a question of how to pass an IntPtr on a queue Passing an unmanaged pointer between two AppDomains (By indirect call) , the answer to this question and the other question will help me taking a design decision.

Community
  • 1
  • 1
Adam
  • 3,872
  • 6
  • 36
  • 66
  • Are you using the System.IO.MemoryMappedFiles.MemoryMappedFile class to share memory between processes? – Panos Rontogiannis May 10 '13 at 09:59
  • @PanosRontogiannis No, should I? – Adam May 10 '13 at 10:32
  • Yes, have a look at it. Check this simple intro http://www.c-sharpcorner.com/UploadFile/b942f9/using-memory-mapped-files/ – Panos Rontogiannis May 10 '13 at 10:41
  • If the AppDomains are in the same process and the memory is unmanaged and also in the same process, then the pointer should be valid in both AppDomains and using memory mapped files shouldn't be necessary. – James Thurley May 10 '13 at 14:01
  • @JamesThurley Please correct me if I am wrong, if one process is hosted under Windows Activation Service and the other one is under a Windows service, then they are two appdomains. Right? – Adam May 10 '13 at 15:50
  • @PanosRontogiannis I never new about MemoryMappedFile, but thanks to you, I do know now. However, I have no control over my 4 GB unmanaged array, I only have a pointer to it as it gets created via a PInvoke method. – Adam May 10 '13 at 15:56
  • @Adam Copy it on disk asynchronously and then use the path. It will take a couple of minutes more but it will work. If this is not an option, try to rephrase the question to attract more people. If you already have a working, but slow solution (like copying it on disk) then mention it and add the optimization tag. – Panos Rontogiannis May 10 '13 at 18:23
  • If I want to copy it to disk, I would have created a managed array out of the pointer (with unsafe code) then passed it to the service. I am trying not to duplicate the memory and pass the pointer as is. – Adam May 10 '13 at 19:17

0 Answers0