Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. XML Deserialisation to slow..

XML Deserialisation to slow..

Scheduled Pinned Locked Moved ASP.NET
csharptutorialdatabasemysql
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hakervytas
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups