locked
serialize and deserialize of an object of huge data RRS feed

  • Question

  • my serialize and deserialize code is this it is giving out of memory exception for huge data..

    public static byte[] seriaize(object obj)

    {

    BinaryFormatter oBinFormater = new BinaryFormatter();
      MemoryStream oStream = new MemoryStream();
       oBinFormater.Serialize(oStream, obj);
       Byte[] buffer = oStream.GetBuffer();
        oStream.Dispose();
        return buffer;

    }

    public static byte[] seriaize(byte [] obj){

    BinaryFormatter oBinFormater = new BinaryFormatter();
                MemoryStream oStream = new MemoryStream(byteArray);
                object obj = oBinFormater.Deserialize(oStream);
                oStream.Dispose();
                return obj;

    }

    plz help...


    vvs

    • Moved by CoolDadTxModerator Tuesday, November 27, 2012 2:55 PM Serialization related (From:Visual C# IDE)
    Tuesday, November 27, 2012 6:09 AM

All replies

  • If this is an intermediate array of bytes, then use another kind of streams. For example if you want to write to file, the try FileStream instead of MemoryStream.

    Why do you need the array of bytes?


    • Edited by Viorel_MVP Tuesday, November 27, 2012 8:19 AM
    • Proposed as answer by Pantelis44999 Tuesday, November 27, 2012 11:39 PM
    Tuesday, November 27, 2012 7:53 AM