Write to SD card in blocks of 512

Does SdFat print function write data in blocks, or loop through each char in the array and write it?

size_t StdioStream::print	(const char * 	str	)

We need to write data in blocks of 512. Do we have to do raw writing as createContiguous, or there is easier way to do this?

Thanks!

A page is 512 bytes. Data is written as full pages when card is actually written to.
Write happens when file is closed or flushed

Thanks for the reply.

char buffer[512];
myFile = SD.open(csvPath,  O_WRITE | O_CREAT | O_APPEND);
myFile.print(buffer);
myFile.close();

From my understanding, the print function in SD library (as in the above code) contain a for loop that go through each char of the buffer and write it to file individually. Thus if buffer size is 512, the number of IO would be 512.

I want to make sure that data is written in blocks of 512 at one time, so I'm wondering if SdFat print function guarantee that? I looked at the internal of print() and still found the loop.

The interface is SPI (single data-line used) An 8-bit cpu writes bytes.

Maybe you dont need the 512bytes buffer (it is there, 'hidden' by the library)
Do some timing.. I dont think you will be able to make it write faster with the additional buffer.

You can write continiously. Every time you reach a 'new' page the 512 byte buffer is written to SD-card.
(you may experience the short delay while this happens)