UnknownError_Num 8:MemoryMappedFile

时间:2011-07-05 07:06:16

标签: c# file-mapping

使用以下代码时无法使用MemoryMappedFile。

    static int NoOfChannels = 1164;
    static int NoOfRows = 64;
    static int N = NoOfChannels * NoOfRows;
    static int NoOfProjections = 10000;
    static long val = (long)NoOfChannels * NoOfRows * NoOfProjections * 4;
    static FileStream stream = null;

    stream = new FileStream("D:\\TEST.DAT", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, 10);
        stream.SetLength(val);

MemoryMappedFile m = MemoryMappedFile.CreateFromFile(stream, "XXXX", stream.Length,    MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.None, true);

        for (int i = 0; i < NoOfProjections; i++)
        {
            long Pos = (long)(i * N * 4);

            MemoryMappedViewStream s = m.CreateViewStream(Pos, N * 4);
        }

使用此代码会导致错误UnknownError_Num 8.如果我将NoOfChannels限制为较小的值,则不会出现错误。我的系统中有32GB,因此分配这些数据时应该没有问题。

有人经历过这样的行为吗?

由于 马丁

0 个答案:

没有答案