jump table

JesseW

Active Member
Licensed User
Longtime User
Erel, is there a way to immediately jump to a certain sub based on the value of a variable? Not cycling through a select statement or a series of elseif's, I mean in one quick and dirty step, based on a value jump to a specific sub. Almost like an on goto statement. Im visualizing an indirect offset jump in assembly and wondering if that concept can be applied to b4a. This vehicle would be the central hub for an app im designing, that would cycle hundreds of times a second, so any time spent deciding where to go based on comparisons would be wasted.

Any ideas?
jesse
 
Last edited:

JesseW

Active Member
Licensed User
Longtime User
Cool. Thanks Andrew :) the perfect solution would be an array of function pointers like can be done in c++.

I'm wondering how much overhead will be in a CallSub statement... Isn't it still going to have to search through a table of sub names? Or am I missing something?

At any rate, your time an involvement is much appreciated
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
The perfect solution would be an array of function pointers like can be done in c++.
There are no pointers in managed environments like Java, at least none accessible by application programmers.
Isn't it still going to have to search through a table of sub names?
No, it would use the Basic4android event structure which uses a Map (Java-speak for Hashtable) but I'll wait and see what Erel says about including it in Basic4android.
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
There are no pointers in managed environments like Java, at least none accessible by application programmers.

oh I know.. I was just wishing outloud and got caught :)

No, it would use the Basic4android event structure which uses a Map (Java-speak for Hashtable) but I'll wait and see what Erel says about including it in Basic4android.

Now you have my attention :) I'll keep an eye on this thread - thanks Andrew

Jesse
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
I've been researching java jump tables, and there is a TableSwitch bytecode opcode, which is a jump table. But the switch statement for most compilers must be based on an integer enum type to avoid the switch statement from being coded as a series of if statements. So... a properly coded java switch statement can provide almost instantaneous execution to multiple. Considering a map invokes a hash function to lookup the value, how much performance will be lost vs. a (almost) primitive jump table? I'm wondering if I should be considering java for my idea cause performance is of the absolute utmost importance. But dang, I hate the thought of learning Java :( I already know Basic, and B4A is such a wonderful tool... :)

Erel, I'm really hoping the upcoming Select Case structure will be able to compile down to a Java switch that would then compile down to a tableswitch sequence. Do you have any comments regarding performance of the two discussed methods?

Jesse
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Under Android the compiled Java bytecode is converted to a different set of bytecodes that are interpeted by the Android Dalvik runtime virtual machine which is register rather than stack-based like Java VMs. So trying to infer Android low level performance from descriptions of Java bytecodes is probably somewhat futile. Android does not implement a Java runtime at all, it just uses the free Java tools as a stepping stone to it's own Dalvik virtual machine.

Android is not a high perfomance environment, at least in versions prior to 2.2 which did introduce a Just In Time compiler, as Dalvik bytecodes are interpreted. This is reported, but I have no first hand experience, to give a four or five fold increase in performance. From my experience of porting my existing C# code, which was truly compiled when running under the .NET Compact Framework, to Android your previous statement of wanting to achieve cycles of "hundreds of times a second" is probably not achievable unless the operations are very simple.
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
Thanks Andrew. Your replies are always very thoughtful. I guess I'll just try it with the new CallSub, when it comes out, and see what happens. If it doesn't measure up, nothing lost but some time.

Jesse
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
Erel, is CallSub() implemented in the v1.1 update? I type it in the b4a ide, but it doesn't turn blue.
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
Erel, thank you for implementing the CallSub() function :sign0060:

Is there a way to use the adjustResize parameter on an activity object for autosizing scrollviews?

Thanks... Jesse
 
Upvote 0
Top