vb内存映射文件整数数组

时间:2017-09-25 06:51:56

标签: arrays vb.net integer mapped-memory

我试图在内存映射文件中创建一个Integers数组并用C ++读取文件,但我不想在这里问c ++部分。 MakeMem()有{"缓冲区中没有足够的可用空间。"}

Private Sub MakeMem()
Dim integer2 = New Integer(31) {}
For j As Integer = 0 To integer2.Length - 1
        integer2(j) = 35 - j
Next
MemoryMappedFile.CreateOrOpen("0MemF", integer2.Length + 1).CreateViewAccessor(0, integer2.Length).WriteArray(Of Integer)(0, integer2, 0, integer2.Length)
End Sub

首先在VB中测试,从内存中读取数组

Private Sub ReadMem()
    Try
        Dim integer3 = New Integer(31) {}

        MemoryMappedFile.OpenExisting("0MemF").CreateViewAccessor(0, integer3.Length + 1).ReadArray(Of Integer)(0, integer3, 0, integer3.Length)

                TextBox1.Text = ""
                For i As Integer = 0 To integer3.Length - 1
                    TextBox1.AppendText(CStr(integer3(i)) + " ")
                Next


            End Using
        End Using
    Catch noFile As FileNotFoundException

        TextBox1.Text = "Mem-map not found"
    Catch Ex As Exception

    End Try
End Sub

0 个答案:

没有答案