March 01, 2021, 10:44:35 PM

Author Topic: [bmx] Get size of type in bytes by BlitzSupport [ 1+ years ago ]  (Read 452 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Get size of type in bytes
Author : BlitzSupport
Posted : 1+ years ago

Description : 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:

Code: [Select]
CreateBank (SizeOf (OOPS_HAVENT_GOT_AN_INT_HANDY) * 2)


Just do SizeOf (Type (Null value for type -- 0 for numbers, Null for Blitz types))... [/i]

Code :
Code: BlitzMax
  1. Print SizeOf (Byte (0))
  2. Print SizeOf (Short (0))
  3. Print SizeOf (Int (0))
  4. Print SizeOf (Long (0))
  5. Print SizeOf (Float (0))
  6. Print SizeOf (Double (0))
  7.  
  8. ' Bonus ball! Size of type...
  9.  
  10. ' Example type/class...
  11.  
  12. Type Test
  13.         Field temp1:Int         ' 4 bytes
  14.         Field temp2:Short       ' 2 bytes
  15. End Type
  16.  
  17. Print SizeOf (Test (Null))


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal