Controlling data flow to or from the memory in relation to the amount of data