Native Types, Bufs and Performance-Sensitive Code
Native types trade flexibility (they can't be undefined, have fixed sizes, and can overflow) for speed and memory efficiency. Use them in hot loops and for binary/FFI work.
my int $i = 0; # native integer (no boxing, faster in tight loops)
my num $total = 0e0; # native float
loop (my int $j = 0; $j < 1_000_000; $j++) { $i = $i + $j }
say $i;
my int @arr = 1..10; # native array (compact memory)
my num32 @floats = 1.5e0, 2.5e0;
say @arr.sum;
my Buf $buf = Buf.new(72, 101, 108, 108, 111);
say $buf.decode; # Hello
my $blob = 'Raku'.encode; # Blob (immutable)
say $blob.elems, ' ', $blob[0]; # 4 82
my buf8 $b8 .= new(0 xx 4);
$b8.write-uint32(0, 0xDEADBEEF, BigEndian);
say $b8.list.fmt('%02X', ''); # DEADBEEF
say $b8.read-uint16(0, BigEndian).base(16); # DEAD
my $packed = Blob.new(1, 2, 3) ~ Blob.new(4); # concatenation