Any ideas how to improve deserialisation for binary data when reading from file for DataTable. Becouse I tested deserialisation from binarry file and compared with the same data using MySql Database and got strange results that from Database reads and fills ~2x times faster to DataTable then Deserialise and read from finary file stream. I serealised as binary data of DataTable to file. I tested deserialisation and the same functions for SortedArrayList and similar HashTable arrays works ~6x times faster that reading the same data from Database. May anybody know how to improve deserialisation or are exist any algorithms for DataTables or DataSets a lot faster then I founded method? Here a code example in VB.NET that I use for deserialisation of binary data from file for DataTable:
Public Shared Function DeserializeByte(ByVal b As Byte()) As Object
If b Is Nothing Then Return Nothing
Dim f As Runtime.Serialization.IFormatter
Dim ms As System.IO.MemoryStream = Nothing
Dim obj As Object = Nothing
Try
f = New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
ms = New System.IO.MemoryStream(b)
obj = f.Deserialize(ms)
Catch ex As Exception
Finally
If Not ms Is Nothing Then
ms.Close()
ms.Dispose()
End If
End Try
Return obj
End Function
And here file reading, may nead improve:
Public Shared Function ReadBytesFromFile(ByVal sFileName As String) As Byte()
Dim b As Byte() = New Byte() {}
Dim fs As System.IO.FileStream = Nothing
Dim iLen As Integer = 0
Try
fs = New System.IO.FileStream(sFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)
iLen = CType(fs.Length, Integer)
b = New Byte(iLen) {}
fs.Read(b, 0, iLen)
Catch ex As Exception
Finally
If Not fs Is Nothing Then
fs.Close()
fs.Dispose()
End If
End Try
Return b
End Function
Here translated code for C# users:
public static object DeserializeByte(byte[] b)
{
if (b == null) return null;
Runtime.Serialization.IFormatter f;
System.IO.MemoryStream ms = null;
object obj = null;
try {
f = new Runtime.Serialization.Formatters.Binary.BinaryFormatter();
ms = new System.IO.MemoryStream(b);
obj = f.Deseriali