Determine Size of Typed variables

Steven Sparrow

Member
Licensed User
Longtime User
Hi Erel,

We use a lot of structures in our applications, as we communicate with remote Bluetooth and WiFi devices; marshalling structures etc.

Would it be possible to provide a method that allows us to retrieve the size of a Typed variable (in bytes). This would be especially useful in the case of "Typed" variables that which contain dozens of fields and other Typed variables. We don't want to hard-code the size if possible as it makes the code more difficult to mainain.

As an example:
B4X:
Type RSP_GET_STATS_T (Command, Dummy As Byte, Result As Short, LastError As Short, Bearing, AddrLie, AddrPress, CorrTwist As Float, _
AddrMatrix As S16Matrix3X3T, SwingArc As Float, ImpType As Short, ImpFaceAngle, ImpPathAngle, ImpShaftAngle, ImpLieAngle, AttackAngle As Float, _
SOSRec, TOSRec, ImpRec As Short, MaxMph, ImpMph As Float, BackMs, DownMs, Checksum As Short)

Dim Stats As RSP_GET_STATS_T;
Dim length as int : Length = Stats.Size

Someone may have asked this before, but I tried searcfing the forums for sizeof, .length and .size related questions and drew a blank.

Thanks in advance,
Steve
 

Steven Sparrow

Member
Licensed User
Longtime User
Erel,

Thanks for the clarification.

As there are no "structs" in B4A, I was hoping there might be a way to iterate through the Typed variable elements and accumulate the sum of each elemt's size (e.g. short = 2, long=4 etc); not to worry.

Also, I found no issue with the format of my Type structure; it seems you do not have to specify a Type for each element and can group similar objects with a single declaratioon. We have been using it extensively without error.. unless we've overlooked something ?

Keep up the great work.. !

Regards,
Steve
 
Upvote 0
Top