user61955: So Arduino Mega has Serial, Serial1, Serial2, Serial3.
However, does those Serial lines use the same buffer? or four independent ones? i.e. are they truly receive single independently, or actually some sort of software sharing? How will that affect the coding?

user37622: Every instance of class HardwareSerial has own buffers. Here you can see it in source code. The instances are declared/definded at the end of the HardwareSerial.h/.cpp.

user42015: Actually there are 2 buffers per Serial hardware interface: The hardware buffer, that is 1 byte (per direction of data transfer). The Serial library then transfers this byte in an extra buffer (64 bytes big) from an ISR. Every hardware Serial interface (Serial and Serial1 to 3 on the Mega) has it's own hardware buffer.
Then the Serial library is implemented as a class. Every hardware Serial interface get's it's own instance of this class, including the 64 byte buffer.
So the hardware and the memory is completely seperated. The only thing, what they share, is the CPU time for servicing the interrupts, which is no problem, until you are doing somehting very wrong with interrupts.

61955: <p>So Arduino Mega has Serial, Serial1, Serial2, Serial3.</p>

<p>However, does those Serial lines use the same buffer? or four independent ones? i.e. are they truly receive single independently, or actually some sort of software sharing? How will that affect the coding?</p>
 37622: <p>Every instance of class HardwareSerial has own buffers. <a href="https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/HardwareSerial.h" rel="nofollow noreferrer">Here</a> you can see it in source code. The instances are declared/definded at the end of the HardwareSerial.h/.cpp.</p>
 42015: <p>Actually there are 2 buffers per Serial hardware interface: The hardware buffer, that is 1 byte (per direction of data transfer). The Serial library then transfers this byte in an extra buffer (64 bytes big) from an ISR. Every hardware Serial interface (<code>Serial</code> and <code>Serial1</code> to 3 on the Mega) has it's own hardware buffer.</p>

<p>Then the <code>Serial</code> library is implemented as a class. Every hardware Serial interface get's it's own instance of this class, including the 64 byte buffer.</p>

<p>So the hardware and the memory is completely seperated. The only thing, what they share, is the CPU time for servicing the interrupts, which is no problem, until you are doing somehting very wrong with interrupts.</p>
