Howdy!
First off, I'm not after the most efficient way to plot
a pixel. The following code snippets should help
illustrate what I'm thinking and both do the same
thing.
Here we go:
From my understanding, with each and every call to the
putPixel function, we're instantiating a new Reflector
object. With the end of the function, this object internally
gets marked as not needed anymore and Java's garbage collector
takes care of it, whenever it feels like. Well, this might
take a while and fill up the memory with lots of useless
objects. Or even worse, do this objects remain in the system
memory?
To cut a long story short, would it be better to instantiate a
'global' Reflector object once and reuse it.
A little something like this:
regards,
obscure
First off, I'm not after the most efficient way to plot
a pixel. The following code snippets should help
illustrate what I'm thinking and both do the same
thing.
Here we go:
B4X:
Sub Activity_Create(FirstTime As Boolean)
For a=0 To 50
putPixel(Rnd(0,20),Rnd(0,20))
Next
End Sub
Sub putPixel(xPos As Int, yPos As Int)
Dim reflection As Reflector
reflection.Target = mainCanvas.Bitmap
reflection.RunMethod4("setPixel", Array As Object(xPos,yPos,0xffffffff), Array As String("java.lang.int","java.lang.int","java.lang.int"))
End Sub
putPixel function, we're instantiating a new Reflector
object. With the end of the function, this object internally
gets marked as not needed anymore and Java's garbage collector
takes care of it, whenever it feels like. Well, this might
take a while and fill up the memory with lots of useless
objects. Or even worse, do this objects remain in the system
memory?
To cut a long story short, would it be better to instantiate a
'global' Reflector object once and reuse it.
A little something like this:
B4X:
Sub Globals
Dim globalReflector As Reflector
End Sub
Sub Activity_Create(FirstTime As Boolean)
For a=0 To 50
putPixel(Rnd(0,20),Rnd(0,20))
Next
End Sub
Sub putPixel(xPos As Int, yPos As Int)
globalReflector.Target = mainCanvas.Bitmap
globalReflector.RunMethod4("setPixel", Array As Object(xPos,yPos,0xffffffff), Array As String("java.lang.int","java.lang.int","java.lang.int"))
End Sub
regards,
obscure