没搞清楚你这么干的意义up
jf

解决方案 »

  1.   

    要得到这个字节流干嘛呢,要持久化的话做对象序列话就可以。
    实在想看内存,VMMap这个工具也许能提供点提示
      

  2.   

    二进制序列化
    public byte[] SerializeObject(object pObj)
            {
                if (pObj == null)
                    return null;
                System.IO.MemoryStream _memory = new System.IO.MemoryStream();
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(_memory, pObj);
                _memory.Position = 0;
                byte[] read = new byte[_memory.Length];
                _memory.Read(read, 0, read.Length);
                _memory.Close();
                return read;
            }
      

  3.   


    //实例类
    [Serializable]
    public class MyObject {
      public int n1 = 0;
      public int n2 = 0;
      public String str = null;
    }以下代码示例说明该类的实例是如何被序列化到一个文件中的。
    MyObject obj = new MyObject();
    obj.n1 = 1;
    obj.n2 = 24;
    obj.str = "Some String";
    IFormatter formatter = new BinaryFormatter();
    Stream stream = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None);
    formatter.Serialize(stream, obj);
    stream.Close();
      

  4.   

    参考也用C#做个视频监控客户端来玩玩,   一般C++下我们进行网络传输模块开发,会采用结构体来封装组织通信报文,那采用C#开发的客户端程序需与服务端通信,就会碰到怎么把一个结构体转成一个byte数组,以及如何把收到的byte数组数据还原成结构体对象.我们这里就涉及到了C#与其它语言的互操作,也就是所谓的 P/Invoke技术,主要也就是System.Runtime.InteropServices命名空间下的Marshal类的使用.(可参考园友 tuyile006文章struct和byte[]相互转换(用Marshal类实现))