Documentation for method reallocate assembled from the following pages:

Role: Buf §

From Buf

(Buf) method reallocate §

method reallocate(Buf:D: Int:D $elems)

Change the number of elements of the Buf, returning the changed Buf. The size of Buf will be adapted depending on the number of $elems specified: if it is smaller than the actual size of the Buf the resulting Buf will be shrunk down, otherwise it will be enlarged to fit the number of $elems. In the case the Buf is enlarged, newly created items will be assigned a Virtual Machine specific null value, therefore you should not rely upon their value since it could be inconsistent across different virtual machines.

my Buf $b .= new(^10);
$b.reallocate(5);
say $b.raku;  # OUTPUT: «Buf.new(0,1,2,3,4)␤» 
 
$b = Buf.new1..3 );
$b.reallocate10 );
$b.raku.say# OUTPUT: «Buf.new(1,2,3,0,0,0,0,0,0,0)␤»