现在 有两个进程 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树组里.. 各位大大帮帮忙..
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树组里.. 各位大大帮帮忙..
直接复制一整快内存,或者填充数据结构啊!!!Marshal有那么多的方法!!!Marshal.copy
Marshal.ReAllocCoTaskMem
Marshal.ReAllocHglobal等等
自己去看MSDN
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.
我问了别人.别人说 Marshl.ReadByte 和Marshal.Copy 内存机制不一样。/ 不懂...
Marshal.ReAllocHglobal等等 好象不切题..