sizeOf()
The sizeOf()
system function returns the compile-time-evaluated size of the type passed in as parameter.
Syntax:
method sizeOf(Type): Integer;
int sizeOf(Type);
func sizeOf(_ Type) -> Int
int sizeOf(Type);
This is particularly useful to determine the storage size for Records/Structs or to determine the bitness of Integer types.
Example:
type
MyRecord = record
FieldA: Integer := 5;
FieldB: Byte;
end;
...
writeLn("sizeOf(MyRecord) = {0}", sizeOf(MyRecord));
writeLn("sizeOf(Boolean) = {0}", sizeOf(Boolean));
writeLn("sizeOf(Byte) = {0}", sizeOf(Byte));
writeLn("sizeOf(Word) = {0}", sizeOf(Word));
writeLn("sizeOf(Integer) = {0}", sizeOf(Integer));
writeLn("sizeOf(Double) = {0}", sizeOf(Double));
public struct MyRecord
{
int FieldA: Integer = 5,
byte FieldB
}
...
writeLn("sizeOf(MyRecord) = {0}", sizeOf(MyRecord));
writeLn("sizeOf(Boolean) = {0}", sizeOf(Boolean));
writeLn("sizeOf(Byte) = {0}", sizeOf(Byte));
writeLn("sizeOf(Word) = {0}", sizeOf(Word));
writeLn("sizeOf(Integer) = {0}", sizeOf(Integer));
writeLn("sizeOf(Double) = {0}", sizeOf(Double));
public struct MyRecord {
Int FieldA: Integer = 5,
Byte FieldB
}
...
writeLn("sizeOf(MyRecord) = {0}", sizeOf(MyRecord))
writeLn("sizeOf(Boolean) = {0}", sizeOf(Boolean))
writeLn("sizeOf(Byte) = {0}", sizeOf(Byte))
writeLn("sizeOf(Word) = {0}", sizeOf(Word))
writeLn("sizeOf(Integer) = {0}", sizeOf(Integer))
writeLn("sizeOf(Double) = {0}", sizeOf(Double))
public struct MyRecord {
int FieldA: Integer = 5,
Byte FieldB
}
...
writeLn("sizeOf(MyRecord) = {0}", sizeOf(MyRecord));
writeLn("sizeOf(Boolean) = {0}", sizeOf(Boolean));
writeLn("sizeOf(Byte) = {0}", sizeOf(Byte));
writeLn("sizeOf(Word) = {0}", sizeOf(Word));
writeLn("sizeOf(Integer) = {0}", sizeOf(Integer));
writeLn("sizeOf(Double) = {0}", sizeOf(Double));
When this method is executed, we see the following results:
sizeOf(MyRecord) = 8
sizeOf(Boolean) = 1
sizeOf(Byte) = 1
sizeOf(Word) = 2
sizeOf(Integer) = 4
sizeOf(Double) = 8
This example illustrates how record fields are placed on integer boundaries by default. The StructLayout
and Packed
aspects can be used to control this behavior.
See Also
typeOf
System Function- Records in Oxygene
- Value Types vs. Reference Types
- Integers
StructLayout
AspectPacked
Aspect