现在 有两个进程 A和B...    A,B共享一块内存块  .这块内存块大小大概 为 1024*768*3   现在A进程向内存块里写速度...B进程从内存块了读数据... 
  B进程是这样从内存块里读数据的:
 
  int[] bit=new int[1024*768*3];
  Intptr intP=new Intptr(0x********);
  for(int i=0;i<=1024*768*3;i++)
   { 
      bit[i]=Marshal.ReadByte(intP,i);
   }
  //现在问题是  这样 一个一个的从内存里读数据,速度很慢.. 怎么样  可以快速的从内存里读取数据并保存在bit树组里..  各位大大帮帮忙..

解决方案 »

  1.   

    有没搞错啊,你居然会一个一个的去读!!!!
    直接复制一整快内存,或者填充数据结构啊!!!Marshal有那么多的方法!!!Marshal.copy
    Marshal.ReAllocCoTaskMem
    Marshal.ReAllocHglobal等等
    自己去看MSDN
      

  2.   

    Copies data from a one-dimensional, managed 32-bit signed integer array to an unmanaged memory pointer. Namespace: System.Runtime.InteropServices
    Assembly: mscorlib (in mscorlib.dll)C# 
    public static void Copy (
    int[] source,
    int startIndex,
    IntPtr destination,
    int length
    )
     Parameters
    source
    The one-dimensional array to copy from. startIndex
    The zero-based index into the array where Copy should start. destination
    The memory pointer to copy to. length
    The number of array elements to copy. 
      

  3.   

    Marshal.Copy复制整个内存块。如果内存块很大,频繁的读写容易产生碎片,而且多个进程容易冲突,建议你在写的时候,先初始化一块内存,把数据连续写入以后,再把它指向被读的那个变量。
      

  4.   

    Marshal.copy   提示内存受保护 ..
    我问了别人.别人说 Marshl.ReadByte  和Marshal.Copy  内存机制不一样。/ 不懂...
      

  5.   

    Marshal.ReAllocCoTaskMem 
    Marshal.ReAllocHglobal等等   好象不切题..