我想使用WriteFile将大(〜500mb)多维数组写入文件(因为BinaryFormatter在写入大东西时非常慢,并且.Net框架中没有其他方法可以编写多维字节数组,只有单字节或一维数组, 并且进行 for 循环和逐字节写入速度很慢)。
然而,事实证明,这是被禁止的:
IOException
The OS handle's position is not what FileStream expected. Do not use a handle simultaneously in one FileStream and in Win32 code or another FileStream. This may cause data loss.
除了在使用 WriteFile 编写后每次想使用 BinaryFormatter 编写时重新打开文件流之外,还有什么办法吗?