Alternatively read and write in memory buffer

thanks