Skip to main content

Practice ยท 2 of 2

ArrayPool discipline

CHALLENGE
Difficulty: advanced+25 XP

Implement static byte[] RentedSum(int[] values, out byte[] rented) โ€” NO. Simpler and testable: implement static long PooledSum(int[] values) that copies values through a rented ArrayPool<byte[]> buffer (rent a byte[] at least 4*values.Length, sum the first values.Length ints from it as 4-byte little-endian groups, return the sum, RETURN the array to the pool in a finally). Then implement static long DirectSum(int[] values) that just sums. Both must return identical results; the pooled one must not allocate a new array per call (the test calls it 100x and checks GC delta is tiny).

Back to lesson: Practice: GC drills