Code archives/Miscellaneous/Get size of type in bytes

This code has been declared by its author to be Public Domain code.

Download source code

Get size of type in bytes by BlitzSupport2013
BlitzMax lets you use SizeOf on an existing variable or object, but what if you just want to check the size of a type without creating one?

For instance, I just found I needed to create a bank the size of two integers:

CreateBank (SizeOf (OOPS_HAVENT_GOT_AN_INT_HANDY) * 2)


Just do SizeOf (Type (Null value for type -- 0 for numbers, Null for Blitz types))...
Print SizeOf (Byte (0))
Print SizeOf (Short (0))
Print SizeOf (Int (0))
Print SizeOf (Long (0))
Print SizeOf (Float (0))
Print SizeOf (Double (0))

' Bonus ball! Size of type...

' Example type/class...

Type Test
	Field temp1:Int		' 4 bytes
	Field temp2:Short	' 2 bytes
End Type

Print SizeOf (Test (Null))

Comments

None.

Code Archives Forum