I have searched but didn't get any exact difference between RAM and a buffer. If both are used for temporary storage, then why they are named differently while both having same property?
3 Answers
Buffer is a concept. It's a structure used to hold data to keep it "closer" while you're processing it. Like buffering a YouTube video. Many types of memories are used as buffers. RAM is certainly great for holding buffers, but for large data you can also buffer data on a hard drive, or an SSD.
Buffers are mainly used to hold data that is costly to read and write (costly in terms of time, or bandwidth, etc), so you'd rather only read a chunk of it once, work on it, then write it back when you're done. And RAM is a good place to do that, unless your data is huge. As you know, current RAM goes from the hundreds of MiB (smartphones) to dozens of GiB (high end PC).
RAM is the specific type of memory. Lots of software uses it to hold buffers, but also to hold its own code, etc.
A buffer is usually used only as temporary storage while something is being transmitted or read. For instance, you might be reading data from a slow-response external storage medium (e.g., a CD) and processing it continuously. In this setting, the first process reads chunks of data from the medium and writes it to the buffer on demand, while the latter reads from the buffer as if it were reading from storage directly. This avoids deadlocks in that the latter process does not need exclusive access to the medium.
In contrast, RAM is simply what is used as main memory for the processes in a general-purpose computer. There might be several buffers not only in RAM but also in other memory units. Saying that RAM is used for "temporary storage" can be rather misleading since "temporary" here actually means "until the process using it is inactive or extinct" (and not "until the data is not needed anymore").
In summary, a buffer is an abstracted concept (and only really exists at the software level); RAM is a concrete type of storage technology.
SSD drives are often used as buffers. You wouldn’t call an SSD drive RAM, would you?
RAM is Random Access Memory. A buffer is a data structure used to optimise the flow of data.
You make a category mistake. You compare things that cannot be compared. It’s like asking why your nose isn’t called Usain Bolt when they are both running.