writing and reading dynamic arrays