Skip to main content

Practice · 1 of 2

Pointer copy with scoped pinning

CHALLENGE
Difficulty: advanced+25 XP

Implement static void CopyBytes(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count) using unsafe pointer arithmetic with fixed — pinning BOTH arrays for the copy. Correctness test does overlapping-free copies at offsets; the lesson: pin narrowly (only the fixed block), never store the pointers, never let them escape.

Back to lesson: Practice: Unsafe drills