简体   繁体   English

将大量float []写入命名管道(或文件)

[英]Write large array of float[] to named pipe (or file)

I am looking for a way to push large amounts of data between 2 processes. 我正在寻找一种在2个进程之间推送大量数据的方法。 The data chunks are blobs of a managed float[] array. 数据块是托管float []数组的Blob。

Currently I am using named pipes to move the data between both processes. 目前,我正在使用命名管道在两个进程之间移动数据。 It works perfectly fine. 它工作得很好。 But unfortunately I seem to need to copy the float[]array into a byte array before I can use the NamedPipe.Write. 但是不幸的是,在使用NamedPipe.Write之前,我似乎需要将float [] array复制到字节数组中。

The blobs are >128MB each, so I prefer to find a solution that works without an extra copying buffer. 每个Blob大于128MB,因此我更喜欢找到一种无需额外复制缓冲区即可工作的解决方案。 Is there any way of achieving the same result without having to do the copy? 有什么方法可以不必复制而达到相同的结果吗?

I was hoping for something like: 我希望有这样的东西:

unsafe{
  fixed(float* fp = myfloatarray){
     pipe.UnsafeWrite(fp, ...)
  }
}

I did poke around to see if I could get the pipe file handle and use WriteFile pinvoke. 我四处摸索看看是否可以获取管道文件句柄并使用WriteFile pinvoke。 It looks like messing around with the file handle of a live managed namedpipe instance is asking for trouble. 看起来像是在处理一个实时托管的命名管道实例的文件句柄在麻烦。

Any tips are very welcome! 任何提示都非常欢迎!

Perhaps it makes more sense to use memory mapped files? 也许使用内存映射文件更有意义? https://msdn.microsoft.com/en-us/library/dd997372(v=vs.110).aspx https://msdn.microsoft.com/zh-CN/library/dd997372(v=vs.110).aspx

I had a look in the source code of the pipestream classes and found that internally the 'Write' methods just wraps around the Win32 WriteFile. 我查看了pipestream类的源代码,发现内部的“ Write”方法只是包裹在Win32 WriteFile中。 So my guess is that the code below should work perfectly fine: 所以我的猜测是下面的代码应该可以正常工作:

unsafe
{
    fixed(float* fp = myfloatarray)
    {
           WriteFile(pipe.SafePipeHandle,(byte*)fp,buffer.Length*sizeof(float), out written);
    }
 }

[DllImport("kernel32.dll", SetLastError = true)]
    static unsafe extern int WriteFile(
        SafeHandle handle,
        byte* bytes,
        uint numBytesToWrite,
        out int numBytesWritten,
        System.Threading.NativeOverlapped* lpOverlapped = null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM