allocate z temp buffer once