单个文件会比依靠文件系统组织更简单,占用更少的物理磁盘空间。只需在文件的开头维护一个偏移量表以链接到每个块。
就压缩而言,应用运行长度编码会明显缩小文件大小,如果它与Minecraft类似,则会依次有很多相同的块。作为奖励,它将在使用拼盘驱动器的计算机上加载速度更快,因为几个字节可以等同于数千个块,而不必为每个块读取一个字节。下面是一个有效的游程编码的快速提示:使用一个命令字节,比如说0x00。所有其他字节都与块关联,但命令字节将表示信息的非块位。传统的行程长度编码是这样的:
Source: AAAABBBBBBBCDDDEFA
Destination: 0x0441074201430344014501460161
Plaintext: .A.B.C.D.E.F.A
使用命令字节,省略这将增加大小的序列:
Source: AAAABBBBBBBCDDDEFA
Destination: 0x00044100074243444444454641.
Plaintext: ..A..BCDDDEFA
这具有在数据的“大理石”部分具有明显的优势。
另一件事,我建议你使用一个系统来存储类似于midi格式的数字,尽管是小尾数格式。为了节省你的谷歌搜索,它的真正意义在于你为每个用于存储数字的字节牺牲了一点。如果第8位被设置,则意味着该数字中有另一个字节,并且级联。例如:
Storing: 65
Stored as: 0x41 (01000001) //The eighth bit is not set, so this number only occupies 7 bits.
Storing: 192
Stored as: 0xC081 (11000000 10000001) //The eighth bit of the first byte is set, so the following byte is part of the number. The second byte doesn't have the eighth bit set, so the number ends there.
Storing: 612453
Stored as: 0x72D825 (11100101 1011000 00100101) //The eighth bit of the first two bytes are set, and the third is not, so this number occupies 3 bytes.
我希望我帮忙提供一些见解。
这可能是[gamedev.se](http://gamedev.stackexchange.com/)更好的问题。 – 2012-03-01 04:34:16