-
Notifications
You must be signed in to change notification settings - Fork 0
Gambas Shared Memory Component Quick Start
This is a Gambas3 component, an must be installed on the users system before it can be referenced.
Public sub main()
with sharedmem
.begin(1512000) ' allocate an area of 1.5 meg, Symbol table size is always 1.5meg about 800 symbols
!Var1 = 1
inc !Var1
!Var1 += 23
print !Var1
!Var2 = true
if !Var2 then Print "that is true"
!Var3 = [1,2,3,4,5,6,7,8] ' arrays and strings should be considered static
' single dimension arrays are special
SharedMem["Var3",4) = 67 ' This is a way to change a single array element.
!Var3 = "this is a stsring"
!Var3 &= "More stuff"
.end()
end with
end
The First instance to open the named memory creates it, every other process/App/Instance simply connects to it and uses it. The named segment is deleted after the last process using it ends.
Public sub main()
with SharedMem
.beginNamed("mymem",4000000) ' add the force close mymem
' if it exists already option
' if you want to create a new mem seg always
!Var1 = 1
inc !Var1
!Var1 += 23
print !Var1
!Var2 = true
if !Var2 then Print "that is true"
!Var3 = [1,2,3,4,5,6,7,8] ' arrays and strings should be considered static single dimension arrays are special
SharedMem["Var3",4) = 67 ' This is a way to change a single array element.
!Var3 = "this is a stsring"
!Var3 &= "More stuff"
.end()
end with
end
ShmMem is object interface not a static interface, this allows use of multiple shared segments in an application, Control over the maxim number of symbols that can be defined within a segment and the timeout when waiting to access a symbol from any task.
The First instance to open the named memory creates it, every other process/App/Instance simply connects to it and uses it. The named segment is deleted after the last process using it ends. Each Process must declare the new Shm() in the same way.
This interface does not require a begin or end call, everything is cleaned up when the assigned variable goes out of scope.
The Memory segment is created as an object the interface Defined as:
Public Sub _new(Optional VarMemLength As Long = VarMemDefault, ' defaults to 2MB
MemName As String = "", ' Defaults to "" local process and tasks only
MaxSymbols As Integer = MaxSymbolsDefault, ' Defaults to 8000 symbols
LockTimeOut As Float = TimeOutDefault) ' Defaults to 0.1 seconds
Public sub Main()
dim MyMem as new ShmMem(4000000,"",50,0.001)
' or
' dim MyMem as new ShmMem() ' to use the defaults
using MyMem
!Var1 = 1
inc !Var1
!Var1 += 23
print !Var1
!Var2 = true
if !Var2 then Print "that is true"
!Var3 = [1,2,3,4,5,6,7,8] ' arrays and strings should be considered static single dimension arrays are special
SharedMem["Var3",4) = 67 ' This is a way to change a single array element.
!Var3 = "this is a stsring"
!Var3 &= "More stuff"
End With
end
The First instance to open the named memory creates it, every other process/App/Instance simply connects to it and uses it. The named segment is deleted after the last process using it ends.
Public sub Main()
dim MyMem as new ShmMem(4000000,"MyStorage",50,0.001)
' or
' dim MyMem as new ShmMem(4000000,"MyStorage") ' to use the defaults
using MyMem
!Var1 = 1
inc !Var1
!Var1 += 23
print !Var1
!Var2 = true
if !Var2 then Print "that is true"
!Var3 = [1,2,3,4,5,6,7,8] ' arrays and strings should be considered static single dimension arrays are special
SharedMem["Var3",4) = 67 ' This is a way to change a single array element.
!Var3 = "this is a stsring"
!Var3 &= "More stuff"
End With
end