Hello all
In some parts of my code, i use Marshal.ReadByte and .WriteByte quite a lot. (And Write/ReadInt16, -32, -64).
However, in .NET2005 they are up to 100 times as slow as in .NET2003. Here's the code i use for testing:
Dim ptr As System.IntPtr = Marshal.AllocHGlobal(50001) Dim Key_nr As Short = 0 Dim loc_cnt As Integer start = Now
For loc_cnt = 1 To 50000 Marshal.WriteByte(ptr, loc_cnt, CByte(loc_cnt Mod 200)) Next
finish = Now
Me.TextBox_WriteByte.Text = (finish.Subtract(start)).TotalMilliseconds.ToString Marshal.FreeHGlobal(ptr)
And i really do need to use these functions...
Even more surprising is the performance difference in the RtlMoveMemory:
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (ByRef Destination As Int16, ByRef Source As IntPtr, ByVal NumBytesToCopy As Integer)
But this is -for myself- less relevant.
Is there any way to get the Read/Write Byte/Int faster
Thanks in advance, Jhn
.NET Development33
|