Android Question Local vs Global object that do not need Initialize

Alessandro71

Well-Known Member
Licensed User
Longtime User
please, don't mind what the actual code does (nothing) but the proof of concept: is there any performance hit in using method "1"?

code sample 1:
declaring the ByteConverter locally to the sub that uses it (more readability, all resources used by the sub are local)

code sample 2:
declaring the ByteConverter once and globally (less readability)

local ByteConverter (1)
B4X:
Public Sub TestSub(data() As Byte)
    For i = 0 To 1000
        ProcessBytes(data)
    Next
End Sub

Public Sub ProcessBytes(data() As Byte)
    Dim bc As ByteConverter
    Log(bc.HexFromBytes(data))
End Sub

global ByteConverter (2)
B4X:
Sub Class_Globals
    Dim bc As ByteConverter
End Sub

Public Sub TestSub(data() As Byte)
    For i = 0 To 1000
        ProcessBytes(data)
    Next
End Sub

Public Sub ProcessBytes(data() As Byte)
    Log(bc.HexFromBytes(data))
End Sub
 
Top