实现不同软件,不同进程共享内存,好比多线程使用全局变量一样道理。
已经增加读写锁,不会因为同时读写发生混乱,也增加了边界检查,避免越界发生软件奔溃
Dim Shared a As 进程通信之内存共享类 = "名字"
只要相同的名字,那么这里的内存就共享了,不管在什么进程中。(注意:当你电脑有多个用户登入,那么跨用户共享,需要在名字前面添加特殊文字,自己查相关资料。)
默认内存大小为 1024 字节,可以自己定义大小
Dim Shared a As 进程通信之内存共享类 = Type("名字",100)
使用共享内存就这样写
a.tLong(0) = 100
Print a.tLong(0)
当然还有其它类型
Declare Property tLong(位置 As ULong) As Long '返回属性 ,“位置”就是在共享内存中的相对位置,从0开始,单位是字节。
Declare Property tLong(位置 As ULong, 值 As Long) '给属性赋值
Declare Property tULong(位置 As ULong) As ULong '返回属性 ,“位置”就是在共享内存中的相对位置,从0开始,单位是字节。
Declare Property tULong(位置 As ULong, 值 As ULong) '给属性赋值
Declare Property tSingle(位置 As ULong) As Single '返回属性 ,“位置”就是在共享内存中的相对位置,从0开始,单位是字节。
Declare Property tSingle(位置 As ULong, 值 As Single) '给属性赋值
Declare Property tDouble(位置 As ULong) As Double '返回属性 ,“位置”就是在共享内存中的相对位置,从0开始,单位是字节。
Declare Property tDouble(位置 As ULong, 值 As Double) '给属性赋值
Declare Property tLongInt(位置 As ULong) As LongInt '返回属性 ,“位置”就是在共享内存中的相对位置,从0开始,单位是字节。
Declare Property tLongInt(位置 As ULong, 值 As LongInt) '给属性赋值
Declare Property tULongInt(位置 As ULong) As ULongInt '返回属性 ,“位置”就是在共享内存中的相对位置,从0开始,单位是字节。
Declare Property tULongInt(位置 As ULong, 值 As ULongInt) '给属性赋值
Declare Property tString(位置 As ULong) As String '返回属性,超过“尺寸”字符会被截断,遇到0也截断,不支持带0 的字符,自己控制字符长度,避免覆盖后面数据
Declare Property tString(位置 As ULong, 值 As String) '给属性赋值
Declare Property tWString(位置 As ULong) As StringW '返回属性,超过“尺寸”字符会被截断,遇到0也截断,不支持带0 的字符,自己控制字符长度(1字符占2字节),避免覆盖后面数据
Declare Property tWString(位置 As ULong, 值 As Wstring) '给属性赋值
这个位置,就是字节为单位,比方 long 类型占4个字节,你要使用 2个 Long 那么
a.tLong(0) = 100 ‘第1个
a.tLong(4) = 100 ‘第2个
因此,共享内存中需要保存什么数据,需要自己计算好位置进行读写。
评论一下?