Update padding function with advice from Karl J. Smith.

Size the padding buffer initially to optimise memory use.