require "fiddle"
include Fiddle
dst = Pointer.malloc(32, RUBY_FREE)
src = Pointer.malloc(4, RUBY_FREE)
dst[0, 32] = "\x00" * 32
src[0, 4] = "\xAA\xBB\xCC\xDD"
# src is only 4 bytes, but 16 bytes are copied.
dst[0, 16] = src
puts dst.to_str(32)
.bytes
.first(16)
.map { |b| "%02x" % b }
.join(" ")
# aa bb cc dd ad 78 00 00 d8 2a a1 98 ad 78 00 00
# (In my environment)