Bits, Bytes, & Memory
It’s been a while since I’ve done a computer science blog, but I’m hoping to make this a habit. Anyways, I need a refresher on some fundamentals so I am going to write them out because I believe that the best way to truly understand a topic is to teach it.
RAM stands for random access memory. It is much faster to read and write than secondary memory sources such as a HDD or SSD. However, RAM is volatile and data is not retained when a computer is turned off and on again. Conceptually, RAM is a set of boxes. Each of these boxes can hold a 0 or a 1.
Say we had an array of integers we needed to store in RAM. Each integer is 4 bytes or 32 bits.
When we store our array in RAM, we store the value 4 first. Note that we don’t actually put base 10 numbers into memory. We are actually writing 4 in base 2. It would be very tedious to represent it in Figure 2 because each value would be 32 digits longs so I am writing it in base 10 for the simplicity's sake.
You may notice that Figure 2’s RAM is different from Figure 1. Figure 2 has an address associated with each value. Since integers are 4 bytes, each contiguous box must be allocated 4 bytes of space. This is why the address goes from $0 to $4 to $8.
Addresses do not need to be allocated in 4-byte increments. Characters are 1 byte in length and the addresses are contiguous while reflecting this. The size or the type of value does not matter as long as memory is allocated correctly and incremented to the type of value being stored.