How to store big variables in a redstone RAM memory?
Solution 1:
While going over how memory works in real life is pretty out of scope for Arqade, rather than chaining memory cells together, you could use a set number of cells for the address and the rest for the data.
So let's say you have 16 8-bit memory cells, and you want to store 16-bit values. Your current solution would be something like this:
# Value NextAdr
0 0000 0001
1 1111 0010
2 0100 0011
3 1111 0000
And so on, meaning for every 16 bits of data you want to store, you have to allocate 32 bits of cells. Instead, use the first cell to specify the two parts of the 16 bit value:
# Addr1 Addr2
0 0001 0010
# Value
1 11110010
2 01000011
Which would only require 24 bits of allocation per 16 bits of data.
You could further improve the efficiency by allocating one static 8-bit cell as a pointer. So, given 16 8-bit memory cells, you could hold 14 16-bit values, with an extra 8-bit cell left over.
Value 1:
Cell 0: 11110000 Cell 1: 01010101
Value 2:
Cell 2: 11110000 Cell 3: 01010101
# Access Value 1
Pointer cell: 0000 0001
# Access Value 2
Pointer cell: 0010 0011
Doing it this way is also scalable. If you need 32-bit values or 32 8-bit cells, assign two 8-bit cells as a pointer; 64-bit values or 64 8-bit cells, assign three cells as a pointer; and so on.
You could save even more space by making assumptions about where the parts of the value are stored. If, for example, the first part of the value is always proceeded by the second half, you don't need to keep track of the second half's address, cutting the pointer size in half:
Value 1:
Cell 0: 11110000 Cell 1: 01010101
Value 2:
Cell 2: 11110000 Cell 3: 01010101
# Access Value 1
Pointer cell: 0000
# Access Value 2
Pointer cell: 0010
Real world memory is a little more complicated than this, but it follows the same principles, and it should give you a good idea of how to improve your memory storage.