Sub Process_Globals
Public DirektverbrauchWork As List
Public NetzbezugWork As List
Public NetzeinspeisungWork As List
End Sub
Sub Activity_Create(FirstTime As Boolean)
Sleep(1500) ' Start execution with a delay
TestSum
Log ("Done")
End Sub
Sub TestSum
Private nRecords As Long = 500000
Private dDirectSumTotal As Double, dSuppliedSumTotal As Double, dDeliveredSumTotal As Double
Private dx As Double
Log ("At start: available memory: " & HeapSize & " MBytes")
' Fill lists with dummy values
DirektverbrauchWork.Initialize
NetzbezugWork.Initialize
NetzeinspeisungWork.Initialize
For i = 0 To nRecords - 1
dx = 0.1 * Rnd(-1000, 1000)
DirektverbrauchWork.Add(dx)
dx = 0.2 * Rnd(-2000, 2000)
NetzbezugWork.Add(dx)
dx = 0.3 * Rnd(-3000, 3000)
NetzeinspeisungWork.Add(dx)
Next
Log ("After filling lists: available memory: " & HeapSize & " MBytes")
' Total sum of all data points of work data
dDirectSumTotal = 0.0
dSuppliedSumTotal = 0.0
dDeliveredSumTotal = 0.0
For i = 0 To nRecords - 1
If i Mod 2000 = 0 Then
Log ("Row "& i & " Available memory: " & HeapSize & " MBytes")
End If
dDirectSumTotal = dDirectSumTotal + DirektverbrauchWork.Get(i)
dSuppliedSumTotal = dSuppliedSumTotal + NetzbezugWork.Get(i)
dDeliveredSumTotal = dDeliveredSumTotal + NetzeinspeisungWork.Get(i)
Next
dDirectSumTotal = dDirectSumTotal / 1000.0
dSuppliedSumTotal = dSuppliedSumTotal / 1000.0
dDeliveredSumTotal = dDeliveredSumTotal / 1000.0
Log (" ")
Log ("Total sums of work data:")
Log (" DirectConsumed: " & dDirectSumTotal & " [kWh]")
Log (" Supplied: " & dSuppliedSumTotal & " [kWh]")
Log (" Delivered: " & dDeliveredSumTotal & " [kWh]")
End Sub
Sub HeapSize () As Long
Private r As Reflector, iMem As Long
r.Target = r.RunStaticMethod("java.lang.Runtime", "getRuntime", Null, Null)
' Available memory
iMem = ((r.RunMethod("maxMemory") - r.RunMethod("totalMemory"))/(1024*1024))
Return iMem
End Sub