sizeof¶
The sizeof
expression returns an Int32
with the size in bytes of a given type. For example:
sizeof(Int32) # => 4
sizeof(Int64) # => 8
For Reference types, the size is the same as the size of a pointer:
# On a 64-bit machine
sizeof(Pointer(Int32)) # => 8
sizeof(String) # => 8
This is because Reference
's memory is allocated on the heap and a pointer to it is passed around. To get the effective size of a class, use instance_sizeof.
The argument to sizeof is a type and is often combined with typeof:
a = 1
sizeof(typeof(a)) # => 4