Controlling data flow to or from the memory in relation to the available memory capacity