Template the allocation functions.